INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Link two Forms

Link two Forms

(OP)
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

RE: Link two Forms

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 --> vba

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:="[ReservationID] = " & Me.ReservationID

End Sub 

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016

RE: Link two Forms

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close