Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,435

    Pre-assign contents of combo box

    A simple form with a combo box. The RowSource is a table of salutations. My OnOpen code is wanting to pre-populate the combo pane with the currently known value, thus:
    Code:
    Me.cboSalutation = DLookup("Salutation", "tblSalutations", "SalID = " & !SalID)
    In Debug, I can see that Me.cboSalutation does in fact have the string value returned by the DLookup, but it DOES NOT display in the combo's pane when the form is displayed. What might I be missing here?



    Maybe this will help:
    Click image for larger version. 

Name:	000.jpg 
Views:	13 
Size:	52.0 KB 
ID:	44315

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,557
    What is a combo "pane"? If you make up your own words for object properties, features, etc. it makes it harder to figure out what you're asking or referring to. You might be meaning the combo list or the combo control itself (when the list is not dropped down). Putting a value in a combo box does not automatically add it to the list if that's what you're suggesting.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,435
    Sorry Micron, I didn't know what else to call it, I do mean
    combo control itself (when the list is not dropped down).
    I'm NOT trying to add a value that's not already in the list, merely want to pre-select an existing table value given that I know the ID of the table record.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,248
    If I undestand you correctly you want to populate the combo with a Salutation description corresponding to the first salutationid. If the combo is setup correctly (bound column 1, column number =2,column widths 0";3", Row Source: "Select SalID,Salutation From tblSalution;") and BOUND then that will happen automatically. If the combo is unbound then you simply supply the ID not the description:

    Me.cboSalutation=!SalID (or Me.SalID)

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,557
    I'd start by getting rid of the ! in SalID, but what is that? A field in the form recordsource, a variable? Is it preceded somewhere by the beginning of a With block? Are you sure the lookup is retrieving the value? I know the technique can work, even if the combo is unbound so something's not right on your form.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,435
    Me.cboSalutation = !SalID
    Thanks Gicu, that did the trick.
    Bill

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,248
    You're very welcome!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 2
    Last Post: 08-30-2018, 04:33 PM
  2. Replies: 2
    Last Post: 07-13-2012, 05:12 AM
  3. Combo boxes that resize to fit contents
    By drexasaurus in forum Access
    Replies: 2
    Last Post: 01-05-2012, 12:47 AM
  4. Assign Combo Box from Main form to Subform
    By tbassngal in forum Forms
    Replies: 5
    Last Post: 07-18-2011, 04:11 PM
  5. Sort Combo Box Contents
    By aputt@ssd.com in forum Programming
    Replies: 3
    Last Post: 12-03-2009, 04:47 PM

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 - Senior Forums