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

Link two Forms 1

Status
Not open for further replies.

cimoli

Technical User
Jul 30, 2010
207
0
0
US
I am having trouble making a command button on the 1st form pull up a 2nd form.
The common field is called ReservationID.

The code below calls up the 2nd form but it is blank just showing the fields with no answers.
So it almost works. No error messages.

Can you see my mistake? Thanks.

-----------------------------------------------------------------------------
This is the code in the command button that is on frmForm1.

Private Sub cmdGetForm2_Click()

' If record not saved, save it
If Me.Dirty Then Me.Dirty = False

' If no ReservationID, do nothing
If IsNull(Me.ReservationID) Then Exit Sub

' Open form filtered. The Me.ReservationID form is frmForm1.

' In the wherecondition, the left side is the frmForm2 and right side is the frmForm1.
' In other words 'TO' and then 'FROM'. To is the frmForm2 and From is frmForm1.


DoCmd.OpenForm "frmForm2", _
WhereCondition:="[forms]![frmForm2]![ReservationID] = " & Me.ReservationID

End Sub
 
Please use TGML for posting code. It makes your posting easier to read.

I would try something like the following which assumes ReservationID is numeric. Also, the default mode of the form shouldn't be Data Entry.

Code:
Private Sub cmdGetForm2_Click()

    [COLOR=#4E9A06]' If record not saved, save it[/color]
    If Me.Dirty Then Me.Dirty = False

   [COLOR=#4E9A06] ' If no ReservationID, do nothing[/color]
    If IsNull(Me.ReservationID) Then Exit Sub

   [COLOR=#4E9A06] ' Open form filtered. The Me.ReservationID form is frmForm1.
    ' In the wherecondition, the left side is the frmForm2 and right side is the frmForm1.
    ' In other words 'TO' and then 'FROM'. To is the frmForm2 and From is frmForm1.[/color]

    DoCmd.OpenForm "frmForm2", _
        [highlight #FCE94F]WhereCondition:="[ReservationID] = " & Me.ReservationID[/highlight]

End Sub

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
Thanks Duane. At first, I thought it did not work.
After I got out of the file and came back in, it all worked.
I did this a few times. Always works now thanks to you Duane.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top