code to create a list for combobox from filter

darbid

Registered User.
Local time
Today, 17:18
Joined
Jun 26, 2008
Messages
1,428
code to create a list for combobox from filter[Solved]

I am sure this can be answered by searching but i do not know what to search for.

Imagine I have two columns. I want to first filter according to one column and then show in the combobox the filtered result from the second.

But I want to do this with VBA code.

Could you please point me in the right direction, even if it is the right words to search.
 
Last edited:
I am sure this can be answered by searching but i do not know what to search for.

Imagine I have two columns. I want to first filter according to one column and then show in the combobox the filtered result from the second.

But I want to do this with VBA code.

Could you please point me in the right direction, even if it is the right words to search.

Please elaborate more on the infos?

Like, cite a situation.

Are these 2 columns same like a tree?

As what i've understood, it is like the one below:

1st Column DB and 1st Combobox:
[1] A1
[2] B1
[3] C1

2nd Column DB and 2nd Combobox:
[1] A21
[2] A22
[3] B21
[4] B22
[5] B23
[6] C21

Situation:
- when "B1" in 1st Combobox is selected,
the values in the list of 2nd Combobox should
ONLY be "B21", "B22" and "B23".

Q: Is my situation same to yours?

(Please correct me if I'm wrong)
 
I think what I am after is very very simple.

The table has many columns.

EG -
Column 1 = V_No.
Column 2 = User
Like this

V_No. - - - - User
1523 - - - - DAB
1623 - - - - DAB
1548 - - - - SCR
1489 - - - - GHT
1898 - - - - DAB

I have a combobox on a form. user DAB opens the form and I want it so that when he clicks on the combobox the list that drops down only shows the V_No. that belong to him. In my example the list would have 3 numbers in it. When SCR opens it he would see only 1548.
 
I'm not sure what you are using to establish the User connected to the Database so I'll just wing it. It sounds like you have the First Combo down pat anyways...:

Establish a Public String Variable name UserName to hold the User Name. Ensure that the the variable is filled when the user logs in or when the first combo choice is selected (best this is stored in a table):

It seems like the User Name is well established before the Form is opened so, in the Forms' OnOpen event, place code that looks something like this:

Code:
Private Sub Form_Open(Cancel As Integer)
   Me.MyCombo2Name.RowSourceType = "Table/Query" [COLOR="DarkGreen"]'Not needed unless you have Combo RowSourceType set to other than Table/Query.[/COLOR]
   Me.MyCombo2Name.RowSource = "SELECT DISTINCT [V_No.] FROM [[I][COLOR="Red"]MyTableName[/COLOR][/I]] WHERE [User]=[B][COLOR="Red"]'[/COLOR][/B]" & UserName & "[B][COLOR="Red"]'[/COLOR][/B] ORDER BY [V_no.];"
End Sub

.
 
Cyberlynx and Keirnus thank you that was what I was looking for.
 

Users who are viewing this thread

Back
Top Bottom