Results 1 to 8 of 8
  1. #1
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26

    How to populate combobox via VBA


    Hello my friends.. I have a bit problem....

    How to populate in combo box?

    Let say for the first row is "-ALL-". Then after the first row, data from the database will be out.

    Because i need to do "IF ELSE statement" in VBA..

    Code:
    If me.comboModel="-ALL-" Then
    'SQL String to list box without "where"
    Else
    'SQL String to list box with where
    End if
    Thanks you...

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I'm unclear as to what you are asking. Are you asking how to add "ALL" to the row source of the combo box? If so, you would base the row source of the combo on a UNION query

    For example if your current row source is like this

    SELECT tblemployees.pkEmpID, txtlastname & " "& txtfirstname AS EMPNAME
    FROM tblemployees

    You would change it to this:

    SELECT tblemployees.pkEmpID, txtlastname & " "& txtfirstname AS EMPNAME
    FROM tblemployees

    UNION
    SELECT 0,"ALL"
    FROM tblEmployees
    ORDER BY pkEMPID


    The UNION query has to be done via SQL view.


    Then you could use the 0 in your IF THEN

    IF me.combomodel=0 THEN...

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    I'm also unclear as to what you are asking. I think you are trying populate a combobox based on it's value itself. I doubt if this can be done.You need another combo box say combo1 and then in the rowsource of your concerned combo box say combo2, use "Like [Forms]![YourFormName]![Combo1] & "*" in the criteria row of the respective field. This can be done through VBA too.

  4. #4
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26

    Exclamation

    Sorry for my bad english...

    this is sample picture..

    Click image for larger version. 

Name:	problemCombo.jpg 
Views:	13 
Size:	57.4 KB 
ID:	8714

    Can see? for first row is write -ALL- and another is come from the table...

    How solved this problem?thanks for help...

  5. #5
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26
    Click image for larger version. 

Name:	problemCombo2.jpg 
Views:	10 
Size:	77.9 KB 
ID:	8715
    One more sample picture

    Click image for larger version. 

Name:	problemCombo3.jpg 
Views:	10 
Size:	75.0 KB 
ID:	8716
    Here there is a problem where when we select FLI, FLI + SMA will also be out. Can we select FLI, FLI only will be out?

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    What I showed earlier will get the All into your combo box. You will have to substitute your own table and field names in place of the table and field names I show in red below

    SELECT tblemployees.pkEmpID, txtlastname & " "& txtfirstname AS EMPNAME
    FROM tblemployees


    UNION
    SELECT 0,"ALL"
    FROM tblEmployees
    ORDER BY pkEMPID

  7. #7
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26
    Ok thanks.. Solved my problem..

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome

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

Similar Threads

  1. Populate a text box based on a combobox selection?
    By Richie27 in forum Programming
    Replies: 4
    Last Post: 04-25-2012, 08:00 AM
  2. Replies: 4
    Last Post: 08-15-2011, 10:06 AM
  3. Populate a field based on combobox selection
    By rscott7706 in forum Access
    Replies: 5
    Last Post: 06-02-2011, 03:18 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 1
    Last Post: 08-14-2009, 08:41 AM

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