• Update Default Value of Combo Box (A2K SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Update Default Value of Combo Box (A2K SR1)

    Author
    Topic
    #368372

    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? confused

    Viewing 0 reply threads
    Author
    Replies
    • #577066

      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.

      • #577159

        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…)

        • #577163

          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.

          • #577204

            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.

            • #577210

              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.

        • #577183

          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.

          • #577203

            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.

            • #577349

              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.

    Viewing 0 reply threads
    Reply To: Update Default Value of Combo Box (A2K SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: