Results 1 to 15 of 15
  1. #1
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52

    A Combo box that open another form

    Good day,
    I have a combo box with a Row Source Type as Value list and Yes;No as row source. If a user selects Yes, it will save the value "Yes" in my table and then opens form. And if its a No it will just go to next control.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    In the after update event of the combo:

    Code:
    If Me.ComboName = "Yes" Then
      DoCmd.OpenForm...
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    If the combobox is bound to a Yes/No field type in a table...

    Typically with a combobox that's bound on a Yes/No field type, for the value list, you have:

    -1;Yes;0;No
    and set the columncount to 2 and the column width's to 0";.75"

    This then saves a -1 or 0 into the Yes/No field in the table.

    If it's not bound to a field, then disregard and follow as pbaldy stated to open the form.

  4. #4
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    Both replies works perfectly.
    However, once the form has been loaded and completed the data entry ..I received this message "You cannot add or change a record because a related record is required in table "tableName'. Its something to do with the EmpID in Table2 (opened form) not being replicated. Please note that EmpID field in table1 (w/ Primary key)and table2 has a one-To-Many relationship. Please help.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    It sounds like the record in the first form might not be saved yet? If not, add this right before opening the other form:

    If Me.Dirty Then Me.Dirty = False
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    pbaldy,
    yes you're right the record in not yet saved in the first form, the combo box is my 3rd field (out of 10). Which event would I use to place the code for the other form, I'm lost.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    You'd place that line immediately before the OpenForm line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    Hi pbaldy,
    I'm still getting the same error.


    Code:
    Private Sub Group_Click()
    If Me.Group = True Then
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm "frmSpouse"
    End If
    End Sub

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    You're getting the error on the second form, right (frmSpouse)? Has whatever field that relates that form to the first been added to the first yet? Has there been enough added to the first for the record to save (missing required fields)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    pbaldy,
    I only get the error on the frmSpouse, please see attached sample file.

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    It's because frmSpouse doesn't have the employee ID. Try this:

    Code:
        If cboGroup.Value = "1" Then
            DoCmd.OpenForm "frmSpouse", , , "EmpID = " & Me.EmpID
            Forms!frmSpouse.EmpID = Me.EmpID
        End If
    The first bit will open the form with any existing matching records, the second will force the employee ID from the first form. Play with those and see how it goes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    I'm getting a "Run-time error '2465' Application-defined or object-defined error" in line:

    Forms!frmSpouse2.EmpID = Me.EmpID

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Where do you have it? I copied that out of your db after I tested it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    pbaldy.
    I just created a subform and apply the code and works perfectly.

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  2. Can you set a combo box to open links?
    By Procom Webserve in forum Access
    Replies: 2
    Last Post: 12-07-2009, 03:11 AM
  3. Combo box open reports
    By GUMUBIBI in forum Programming
    Replies: 5
    Last Post: 09-06-2009, 04:36 PM
  4. Open a form using a query that references a combo
    By accessbobp646 in forum Access
    Replies: 1
    Last Post: 02-22-2009, 09:50 AM
  5. Using combo box to open another form
    By ladyairj23 in forum Forms
    Replies: 0
    Last Post: 06-02-2006, 07:03 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