Results 1 to 7 of 7
  1. #1
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110

    Using VBA code to open form to specific record

    I have a form for entering Competitor Detail on it is a control that displays the competitor's age, based on their birthday as entered in the Contacts table. I've created a button that displays only when the age is null. That button opens the Contact Details form. I have the code set to open the Contact Details form. I need it to open the form for that specific contact and if possible put the focus on the Birth Date control. So far this is what I have

    Private Sub EditBirthday_Click()
    DoCmd.OpenForm "Contact Details"
    End Sub

    The CompetitorDetails form has a control called ID which is the ID of the competitor in the Contacts table and on the Contact Details form. Birth Date is the name of the control on the Contact Details form.



    What do I need to add to my code to get the desired result?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    See if this helps:

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    One way...

    The syntax for the open form command is:

    DoCmd.OpenForm formname[, view][, filtername][, wherecondition][, datamode][, windowmode][, openargs]

    Note the "wherecondition" argument.

    Try:
    DoCmd.OpenForm "Contact Details",,,"[CompetitorID] = " & Me.ControlName

    where "Me.ControlName" is the name of the control on your form that has the PK of the "Competitor".

    --------
    NOTE: Change "CompetitorID" and "ControlName" to your names.
    Last edited by ssanfu; 11-13-2012 at 03:00 PM. Reason: missed a comma :(

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Not fair Paul!!!
    You are faster because you have a web site!!!

  5. #5
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Thanks! That did it as far a opening the correct record. Now if I can get it to put the focus on the Birth Date control on the Contact Details form.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Quote Originally Posted by ssanfu View Post

    Not fair Paul!!!
    You are faster because you have a web site!!!
    I put it on the website because I got tired of typing it all out so many times. You're welcome to post the link.

    Forms!SecondFormName.DesiredControl.SetFocus
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Perfect! Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Open form on specific record
    By iky123 in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 09:56 AM
  2. Replies: 11
    Last Post: 02-01-2012, 01:14 AM
  3. Open form to specific record
    By Two Gun in forum Forms
    Replies: 7
    Last Post: 11-09-2011, 10:00 AM
  4. Open form to a specific record from a query
    By chris.williams in forum Forms
    Replies: 11
    Last Post: 10-06-2011, 04:15 PM
  5. Open Form to Specific Record
    By batowl in forum Forms
    Replies: 1
    Last Post: 04-08-2011, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums