Results 1 to 12 of 12
  1. #1
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117

    Question about Combo Box & Bound Column

    So, I use a Combo Box based on a custom query to apply a filter to some of my continuous format forms. Works well.

    The combo box is set up presently for two columns but only the first column is visible. The first column is the user friendly description and the second column is the Primary Key for the items in the column list.

    When I apply the filter, I use column 2 (Column(1) in the VBA code since it starts at zero for coding purposes) and column 2 is my bound column (the combo box is not bound to a Control Source).

    Now, say I want to carry that filter value to the next or even previous form. I decided to make a Public Variable, "ApiaryFilter" to store the value of the Combo Box.

    Question, since I use Column 2 as the Bound Column on the various forms, do I still need to explicitly call out Column(1) in the code ?

    Would it be better or would it make a difference if I change the order of the columns so that the Primary Key was actually in the first column and the descriptive test in the second column and just adjust my column width values accordingly ? (I currently have column 2 at zero width so only the text shows in the drop down)

    My current code doesn't seem to be working correctly


    Code:
    ApiaryFilter = Combo_Filter_by_Apiary.Column(1)
    ApiaryFilter is the Public Variable and Combo_Filter_By_Apiary is the combo box name.

    If I leave off the .column(1) would it automatically select the bound column ?

    I probably made this more confusing by trying to over explain it but, well, hopefully it's understandable.

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    It's far more common ( I would dare to say normal/good practice?) to bind the combo to the first column (Normally a primary key) than the second or subsequent columns, and simply hide the first column.

    Referring to the combo in a query will only refer to the bound value, you can't use the column reference..
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Yep, I always had the bound column as the first and hidden.
    Often more columns were hidden where I could retrieve associated data from them.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    you can't use the column reference.
    Pretty sure you can if you wrap the reference in Eval(). Not that I disagree on which column should be bound.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Taking the advice and switching the combo box around so the first column is the Primary key and the bound column and simply hide it to show just the text values.

    Tried that and it worked very well.

    Thanks !!

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by ScubaBart View Post
    Taking the advice and switching the combo box around so the first column is the Primary key and the bound column and simply hide it to show just the text values.

    Tried that and it worked very well.

    Thanks !!
    That is just a matter of preference and standardisation?
    The bound column is always the value in the combo.

    Make sure you have done it to all combos in that case.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Quote Originally Posted by Welshgasman View Post
    That is just a matter of preference and standardisation?
    The bound column is always the value in the combo.

    Make sure you have done it to all combos in that case.
    Yes, going through and doing it to all combos to be consistent (and proper).

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Quote Originally Posted by Micron View Post
    Pretty sure you can if you wrap the reference in Eval().
    Tried this and just get "Undefined function" error when trying to open query in datasheet.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Pretty sure I have done it; would have to find it just to be sure. Will take a while.
    Or as per post 5 (?) here https://www.tek-tips.com/threads/ref...-query.911842/
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Ah, I forgot the quote marks.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Thought we've been here before. Turns out we have
    https://www.accessforums.net/showthr...500#post523500
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    LOL, shows how often I use Eval() - never!
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-19-2021, 05:54 PM
  2. Replies: 10
    Last Post: 03-16-2018, 08:26 AM
  3. Replies: 14
    Last Post: 07-13-2015, 12:47 PM
  4. Replies: 6
    Last Post: 01-30-2014, 05:57 PM
  5. Replies: 1
    Last Post: 12-08-2011, 08: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