Results 1 to 6 of 6

Thread: combo boxes - query

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    combo boxes - query

    Hi, I have a problem regarding combo boxes. I want to add a combo box to a form such that when any item on it is selected the remaining text fields on the form are automically filled from a table depending upon the selected item.

    For example, if the combo box has a list of products. When the user selects a particular product and presses go, the text fields on the same form are filled up with the product details (by looking up a table based on the selected product). I am a looking for a solution without the use of subforms.

    Thanks

  2. #2
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Lightbulb Re: combo boxes - query

    i think u can use a sql query to get all the required data...
    but...
    chk the attachment...this is the most easiest way ..I belive...

    All the best
    Attached Files Attached Files
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: combo boxes - query

    Thanks a lot Sri, I got the idea through your attachment. Can you also perhaps tell me how can I use a query for the solution. Thanks

  4. #4
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Lightbulb Re: combo boxes - query

    VB Code:
    1. Private Sub Combo0_AfterUpdate()
    2. Dim sql As String
    3. Dim rst As Recordset
    4. sql = "Select empname from table1 where empno=" & Me.Combo0.Value & ";"
    5. Set rst = CurrentDb.OpenRecordset(sql)
    6. If Not rst.RecordCount = 0 Then
    7.     Me.Text4 = rst!empname
    8. End If
    9. End Sub

    chk out this...but..comparitivly this code will take more time than previous one..
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: combo boxes - query

    thanks sri, you were great

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: combo boxes - query

    Optimisation hint:
    If you run a query to fill the list box, then fill it with the other data you want to display on the form, but in hidden columns (column widths of 0).
    Then as the user selects the item from the dropdown, you use after update or click events to take the hidden columns data of the selected item and put it into the text box fields on the form. Makes it look faster on seleccting, but a little slower (negligable) on filling the dropdown.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width