Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Open form with linked record

    I have a form named frm_main with the primary key set to GirlID and I want to open another form that uses the same table, just a different query for its recordset.The other form also has GirlID in the query. I want to open the form named frm_special and go to the corresponding record on my main form. Here is my code to open the form.
    On Error GoTo Err_Command122_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_morepictures"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command122_Click:
    Exit Sub

    Err_Command122_Click:
    MsgBox Err.Description
    Resume Exit_Command122_Click

    How can I do this ?

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    How you do this depends on what you want to do after opening the secondary Form. Do you only want to work with the matching Record, or do you want to automatically go to the matching Record but be able to work with other Records, as well, while you have it open?

    Also, what Datatype is the GirlID Field, Text or Number?

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2011
    Posts
    413
    I just want to open to the matching record. The first option is what I want. Thanks

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You didn't give the Datatype of the GirlID Field, as requested, so here is the syntax for both Text and Number Datatypes. Be sure to use the correct one for your Datatype:

    If GirlID is Text

    Code:
    Private Sub btnOpenForm2Record_Click()
     
     If Me.Dirty Then Me.Dirty = False
     DoCmd.OpenForm "SecondaryForm", , , "[GirlID]= '" & Me.GirlID & "'"
    
    End Sub
    If GirlID is Numeric

    Code:
    Private Sub btnOpenForm2Record_Click()
     
     If Me.Dirty Then Me.Dirty = False
     DoCmd.OpenForm "SecondaryForm", , , "[GirlID]= " & Me.GirlID
    
    End Sub


    Replace SecondaryForm with the actual name of your secondary Form and ditto the Command Button I named btnOpenForm2Record.

    Linq ;0)>
    Last edited by Missinglinq; 08-12-12 at 17:47.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2011
    Posts
    413
    Thanks, it worked like a charm and gave me what I wanted.

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad, once again, that we could help!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •