Filter listbox from combo box

valgore

Registered User.
Local time
Today, 12:39
Joined
May 24, 2012
Messages
24
Hello everyone, i've look at other posts about this, and i can't get it to work for my database.
I have a combo box called Employee_ID that is linked to a list box. the list box has a bunch of data that is being pulled from the EmployeeData table. im using the combo box to allow me to sort the listbox by the employee ID.

Here is my code:

Private Sub Employee_ID_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT EmployeeData.[Employee ID], EmployeeData.Date_Day, EmployeeData.Date_Year, EmployeeData.Salary, EmployeeData.Project, EmployeeData.Department, EmployeeData.[Percent Allocated], EmployeeData.[Hours Logged] FROM EmployeeData WHERE EmployeeData" & Me.Employee_ID.Value

Me.List48.RowSource = strSQL
Me.List48.Requery
End Sub

when i run it in debug mode, i can see that it is getting the right record when i hover over the SELECT, but it's not setting it into strSQL. strSQL always = "" and i have no idea why. i thought maybe setting strSQL to String was wrong, so i tried setting it to Integer and still i got = ""
 
Try:

WHERE EmployeeData ='" & Me.Employee_ID & "'"
 
it asks me to pass in Parameter Values for EmployeeData twice still. Any suggestions?
 
When you assign the sql string to the string variable strSQL is the entire sql statement on one line in the code editor?
 
EmployeeData is the name of a table. So your WHERE makes no sense. You need to specify which field needs to have the given value.

When you are not familar with SQL , and obviously you aren't - don't waste your time like this. Build you SQL in the query designer - that will guide you and make sure it works. Then you can copy the code from SQL view into VBA.
 

Users who are viewing this thread

Back
Top Bottom