Results 1 to 3 of 3
  1. #1
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52

    How to save cascading combo box value

    I have 2 cascading combo box (code below), selected values in my 2 combo box are saved in my tblMain under the following fields namely: [Product] and [Description]. Now, I want to add a ProductID (Number) field in my lookup table (tblChoice) and save that value in ProductID field in tblMain. Please help.



    Code:
    Private Sub cboProduct_AfterUpdate()
     Dim strSource     As String
          
      strSource = "SELECT Description " & _
    "FROM tblChoice " & _          
    "WHERE Product = '" & Me.cboProduct & "' ORDER BY Description"
      Me.cboDesc.RowSource = strSource
      Me.cboDesc = vbNullString
          
       End Sub

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    it is a common concept that a business has a list or look up table; i.e. products table and another is perhaps the customer table for repeat customers. these change and are updated occasionally. but the real action is the 'transaction' table - perhaps called a Sales table.

    in the Sales table one selects a Product, and one selects a Customer. there are 2 ways to approach this.

    one way is in defining the fields in the Sales table - by making them to be look up fields that point to their respective list table. the advantage of this approach is if you need a continuous form format for your sales main form. there are disadvantages for professional programmers and some confusing factors if you don't understand/control what is being bound during first set up.

    another way, which you seem to be going toward, is to use Combo/List box to display the look up info. In this case you then need to write the selected data into the fields of the Sales table. So in the 'AfterUpdate' event of the combobox you then put the vba code to write the values to the transaction table fields in the main form. the main form can not be continuous form.

    in this second approach, assuming your main form contains the Sales table fields you can rely on simple write code in the AfterUpdate event like:
    me.CustomerNameField= me.Column(1)

    in your post you are showing a Select query being called in the AfterUpdate. I'm not sure why.

    hope this helps you.

  3. #3
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    it works! , thank you.

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

Similar Threads

  1. Cascading combo boxes
    By combine21 in forum Forms
    Replies: 3
    Last Post: 12-02-2010, 12:57 PM
  2. Default Value for Cascading Combo Box
    By P5C768 in forum Forms
    Replies: 3
    Last Post: 05-06-2010, 03:50 PM
  3. cascading combo
    By rexb in forum Forms
    Replies: 9
    Last Post: 10-26-2009, 04:10 PM
  4. Cascading Combo Boxes
    By desireemm1 in forum Programming
    Replies: 1
    Last Post: 10-05-2009, 06:00 AM
  5. Cascading Combo Box
    By nywi6100 in forum Forms
    Replies: 0
    Last Post: 10-23-2006, 01:45 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