Results 1 to 3 of 3
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Code to open a form


    I'm looking to add an IF statement and not sure how to go about it. I have a form, [frmEmployees]. I need it to open another form [frmEmergencyContact]. However, I need it to open the form to a new entry if there isn't already one there. If there is already a record for that employee, I need it to open the form for that employee. The primary key is [EmployeesID]. I'm not sure how to do it.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    if viewing a list of employees (continuous form), select the record then open the detail form using the ID in the text box (me.EmployeesID)

    docmd.openform "frmEmployees",,,"[EmployeesID]=" & me.EmployeesID

    the emergency contact should be a subform in the detail form:
    frmEmployees. (no need for popups )
    you will SEE that its empty, and can just add as many contacts as you need.

    but if you need a popup form, you can open another form using the same method above to open ONLY that employees ID:
    docmd.openform "frmEmpContacts",,,"[EmployeesID]=" & me.EmployeesID

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Thanks. That seemed to do it.

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

Similar Threads

  1. VBA Code to Open Form
    By kevins in forum Programming
    Replies: 6
    Last Post: 10-23-2012, 06:53 AM
  2. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  3. open form code question
    By budchevy in forum Programming
    Replies: 7
    Last Post: 02-22-2012, 08:56 PM
  4. VB Code to open a form?
    By HeadGasket in forum Access
    Replies: 1
    Last Post: 01-24-2012, 08:26 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 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