Results 1 to 10 of 10
  1. #1
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24

    Subform linking 2 combo boxes does not work

    In my main form I have a subform that has 2 combo boxes that links, cmbCategoryName and cmbExerciseName. This works when I got into the frmSubform but when I am in the main form and try it I receive a popup box: forms!frmProgramDesignSubform.cmbCategoryName

    Once I put in the cmbCategoryName in the popup box I can then choose the ExerciseName related to the CategoryName.

    Help please.

  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,521
    The syntax changes when it's a subform:

    http://access.mvps.org/access/forms/frm0031.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    Thank you. That worked!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    I have used this link many times as a reminder and want to thank you for it.

    Two followup questions if I may, also elementary, but which periodically confuse me:

    1. When "me" is used within a control event, say the after update event for a combobox which is located on a main form, does it refer to the main form or the combobox?

    2. Syntax requirements change when using control variables within a SQL string, eg. one being prepared for use in changing the recordsource of a form. Is there a definitive link/tutorial on this?

    Many thx, Ron

  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,521
    Me always refers to the object the code is in, ie the form. I'm not clear on the second question. Perhaps this?

    http://www.baldyweb.com/BuildSQL.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by pbaldy View Post
    Me always refers to the object the code is in, ie the form. ........
    One reason I was asking is the the first line of the following works for me, but the second, as an alternative, does not:
    Code:
    strWhere = " where tblshoots.Shootsid = forms!frmMain.cboShootName"
     strWhere = " where tblshoots.Shootsid = Me.cboShootName"
    This is in the construction of a SQL fragment in the afterupdate code of a combobox contained in frmMain. So I'm still not clear whether one can categorically use "me" for the form object in all contexts.

    Thanks for the response and the link. -Ron

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That's because Me is only valid within VBA code. When you build and execute the SQL, it's executing outside VBA; JET/ACE has no understanding of "Me". In other words, VBA is building the SQL but then handing it off to be processed by the database engine. Most of us concatenate anyway, which avoids the issue:


    strWhere = " where tblshoots.Shootsid = " & Me.cboShootName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Ah, thanks, that clarifies. I do see a lot of the syntax you show, but have also read that the entire SQL string must be in quotes, so still get confused about when to take that literally.

    Interesting that while JET doesn't get "me" it does understand the "forms!myform.mycontrol" Both are object references. Guess that's just the way it is.

    Thx, Ron

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That link explains it better, but when you concatenate you're still building a string, you're just joining literal text with values from variables or form controls. so

    strWhere = " where tblshoots.Shootsid = " & Me.cboShootName

    resolves to this when passed to the db engine:

    where tblshoots.Shootsid = 123

    And again, Me is a VBA shortcut to the full object reference; it is only understood within VBA.
    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: 10
    Last Post: 03-04-2012, 12:17 AM
  2. SubForm with query conditional combo boxes
    By ThebigCt in forum Forms
    Replies: 1
    Last Post: 02-28-2012, 05:13 PM
  3. Replies: 14
    Last Post: 02-09-2012, 08:33 AM
  4. Replies: 4
    Last Post: 01-22-2012, 10:48 PM
  5. Error with filtering subform using 2 combo boxes
    By dharmacloud in forum Forms
    Replies: 4
    Last Post: 08-22-2011, 10:46 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