Results 1 to 9 of 9
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Update Default Value of Combo Box (A2K SR1)

    Combo1 is on Form1 and is set with a default value. The data for Combo1 is from Table1. The user can select a command button (Command1) on Form1 to update the data in Table1. Combo1 will then show the new data.

    What code would be used to update the default value of Combo1 based on Query1 that extracts a single piece of new data from Table1? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Update Default Value of Combo Box (A2K SR1)

    I'm not sure I understand what you're trying to do. Is the default value a specific item? If all you want to do is set the default value to the first (or only) item in the list, you can use something like this:

    [Combo1] = [Combo1].ItemData(0)

    If you want to set the default value in the property sheet for the combobox, just put the "=[Combo1].ItemData(0)" portion in the DefaultValue property. If the combobox is bound, this will work. If the combobox is unbound, you'll need to use the other method.
    Charlotte

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Update Default Value of Combo Box (A2K SR1)

    Charlotte,

    Thanks for the response. What I am trying to do is this. After the user updates the tables that supply the data for the combo box, I want to change the combo box default setting automatically to a new value. The new value is derived from a separate query on the table supplying the data for the combo box. The combo box has a default value already set.

    Can I set the default value of a combo box equal to the result of a query that only returns one piece of data? (I guess I only needed to ask this question...)
    Regards,

    Gary
    (It's been a while!)

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Update Default Value of Combo Box (A2K SR1)

    Hi Gary,
    Yes you can - you will need to open a recordset based on your query and return the value form the relevant field of that recordset to the defaultvalue property of the combobox. Depending on the nature of your query, it might be easier to use a dlookup (or similar) function to return the value you're after.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Update Default Value of Combo Box (A2K SR1)

    Maybe I'm confused. Default values only apply to new records. Are you trying to set the default value of a bound combobox or an unbound combobox? If it's unbound, you'll have to set the value instead. And if a record already exists, setting the default value of a bound combobox doesn't change anything.
    Charlotte

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Update Default Value of Combo Box (A2K SR1)

    Charlotte,

    Let me try to clarify some more. Can I set the Combo Box properties, Data Tab, Default Value to a value from a query? The combo box is unbound.
    Regards,

    Gary
    (It's been a while!)

  7. #7
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Update Default Value of Combo Box (A2K SR1)

    Rory,

    Under the combo box properties, data tab, default value, I can use Dlookup?? I didn't know this and will give it a try.
    Regards,

    Gary
    (It's been a while!)

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Update Default Value of Combo Box (A2K SR1)

    You can, but depending on what you're trying to achieve it may not be much use. I actually meant you to use DLookup in code so that you could change the criteria as necessary - just saves messing about with recordsets.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Update Default Value of Combo Box (A2K SR1)

    See Rory's reply. The only way I can think of to do what you're apparently trying to do is to use a DLookup or a recordset to retrieve the value and *THEN* set it from code. That is way too much effort to set a default value, which only applies to new records created after that anyhow.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •