Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy value from field in one form to field in another form 1

Status
Not open for further replies.

PamelaD

Technical User
Joined
Feb 15, 2001
Messages
12
Location
US
In Access 2000, I am working with two tables:

tblContacts
lngContactID [PK]
strNameLast
strNameFirst
strAddress
strCity

tblMemberships
lngMembershipID [PK]
dtmDateJoined
strMembershipName
strMembershipType
lngContactID [FK]

Two forms:
frmPersons [record source = tblContacts]
frmAddMembership [pop-up form, record source = tblMemberships]

I want to place a command button [cmdAddMembership] on frmPersons that when clicked, will open frmAddMembership in a new record with lngContactID filled in with the same lngContactID as was on frmPersons.

Here’s the code that I have, minus the bits that require copying lngContactID to frmAddMembership:


Private Sub cmdAddMembership_Click()

'Open frmAddMembership to a new record
DoCmd.OpenForm "frmAddMembership"
DoCmd.GoToRecord , , acNewRec

'Move cursor to the Membership Name field
Forms![frmAddMembership].[strMembershipName].SetFocus

End Sub

I am sure that this is very elementary for people who know what they are doing, but I'm only an interested user (not a techie) and struggling here. I’ve looked through the forum and could not figure out which solution would be appropriate. I would very much appreciate any help on the code required to accomplish this. Thanks in advance.
 
Try this:
Code:
    DoCmd.OpenForm "frmAddMembership", , , , acFormAdd
    Forms!frmAddMembership!lngContactID.DefaultValue = """" & lngContactID.Value & """"

The reason I set the DefaultValue rather than the value is so that if the user decides to exit out without making changes, they don't have to first cancel the changes they made. If you want to set the value rather than the default value, then try this:
Code:
    DoCmd.OpenForm "frmAddMembership", , , , acFormAdd
    Forms!frmAddMembership!lngContactID.Value = lngContactID.Value
 
It worked like a charm! Can't thank you enough!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top