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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Value With a Command Button 1

Status
Not open for further replies.

10TR

Technical User
Dec 14, 2009
12
US
Here is my goal:

I have two forms with an command button on the primary that opens the secondary form with the current record ( "roomId" ) on the primary and secondary. The primary form name is: "frm-room" with roomID as the primary key. I want it to set a value to the secondary form "frm-presenter" if a match is not made.

Below is the code I'm using to open matching records on the forms.

DoCmd.OpenForm "frm-presenter" , acNormal, , "roomId=" & Me.roomId

If it matches the number great but if the number is not found then I need it to set the value of the primary ( "roomId" ) with the secondary ( new record ) ( "roomId" )

Any suggestions would be appreciated!

Tony
 
Perhaps something like this ?
DoCmd.OpenForm "frm-presenter" , acNormal, , "roomId=" & Me!roomId
DoEvents
Forms!frm-presenter!roomId.DefaultValue = Me!roomId

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I received a compile error on this line. Any idea what wrong?

Forms!frm-presenter!roomId.DefaultValue = Me!roomId

 
Sorry for the typo:
Forms![frm-presenter]!roomId.DefaultValue = Me!roomId

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That works perfect!!! Thanks
 
I had to add one more line of code on the first line. I was getting an error message concerning relationships in the database. Refresh.Me corrected the problem. Thanks again for all your help.

Private Sub Open_Presenter_Form_Click()
Me.Refresh
DoCmd.OpenForm "frm-presenter", acNormal, , "roomId=" & Me.roomId
DoEvents
Forms![frm-presenter]!roomId.DefaultValue = Me!roomId

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top