Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2015
    Posts
    2

    Answered: Adding a new record and not clearing the combobox

    Hi,

    I'm working on creating a sort of a shopping list.
    where the 1st combo box would be the department the item is found in: Fruit and veg, dairy, bakery etc
    the 2nd combobox would be the item name
    the 3rd combobox would be the quantity

    I have managed to get a subform below the comboboxes to show whats already in the basket when a department is selected however when i add a new record the comboboxes are cleared.
    I would like to know if there is a way to keep the first combobox with the value in it as it is rather than clearing everything.

    Thank you

    Paul K

  2. Best Answer
    Posted by Missinglinq

    "Comboboxes #1 and #2 are involved in what is usually called Cascading Comboboxes, and in this type of scenario only the last Combobox in the cascade is usually Bound to a Field in the underlying Table. If you remove the ControlSource from the first Combobox, which is to say make it Unbound, by default the last value selected will be displayed in it when you move to a New Record.

    Is there any reason you need to store the selected department in your Form's underlying Table?

    To let the first Combobox remain Bound to your Form's Table, you can use the AfterUpdate event of the first Combobox to set the DefaultValue for it. From that time forward, until you either manually change the selection or close your form, the data will automatically be displayed in the Combobox in each New Record.

    Code:
    Private Sub FirstComboboxName_AfterUpdate()
       Me.FirstComboboxName.DefaultValue = """" & Me.FirstComboboxName & """"
    End Sub

    This identical syntax is valid for Text, Number, DateTime and Boolean Datatypes.

    Linq ;0)>"


  3. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Comboboxes #1 and #2 are involved in what is usually called Cascading Comboboxes, and in this type of scenario only the last Combobox in the cascade is usually Bound to a Field in the underlying Table. If you remove the ControlSource from the first Combobox, which is to say make it Unbound, by default the last value selected will be displayed in it when you move to a New Record.

    Is there any reason you need to store the selected department in your Form's underlying Table?

    To let the first Combobox remain Bound to your Form's Table, you can use the AfterUpdate event of the first Combobox to set the DefaultValue for it. From that time forward, until you either manually change the selection or close your form, the data will automatically be displayed in the Combobox in each New Record.

    Code:
    Private Sub FirstComboboxName_AfterUpdate()
       Me.FirstComboboxName.DefaultValue = """" & Me.FirstComboboxName & """"
    End Sub

    This identical syntax is valid for Text, Number, DateTime and Boolean Datatypes.

    Linq ;0)>
    Last edited by Missinglinq; 06-18-15 at 11:13.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #3
    Join Date
    Jun 2015
    Posts
    2

    Thank you

    Thank you,

    That code did exactly what I needed, I need to see all the items on the table filtered by department and it works perfect.
    Thank you very much

    Great help

  5. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad we could help!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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