Hi guys, I have a question that has been trying to kill me for the whole day. I'm pretty sure it's not going to be hard for you, if it is possible.
I am trying to run a SELECT query on a table, but I want the WHERE to be defined by a selection in a combo box. So the value for WHERE should be selected by the user. Is that possible?
I will show you what I've done so far.
Private Sub cboSector_Change()
Dim SQL As String
Dim Sector As String
SQL = "SELECT FirstName, Surname, Title FROM AttendanceArchive WHERE SchoolService = cboSector.Text"
lstOutcome.RowSource = SQL
End Sub
No need to tell you I've tried all variations of the more obvious stuff. Changing, rearranging.. didn't help me. I have the feeling I'm missing something very basic.. or it might not be possible.
I chose this path of doing things, because in my old database (Attendance is now being moved to the new one, thus becoming Archive) I have a similar thing, but input comes from an inputbox. The following statement works perfectly fine in my old database.
Private Sub cmdFind_Click()
Dim sql As String
sql = "SELECT FirstName, Surname, Title FROM Attendance WHERE FirstName = EmployeeName OR Surname = EmployeeName"
lstOutcome.RowSource = sql
End Sub
It's been a while since I used VB, so a bit of a helping hand will be grately appreciated.
Thanks in advance
I am trying to run a SELECT query on a table, but I want the WHERE to be defined by a selection in a combo box. So the value for WHERE should be selected by the user. Is that possible?
I will show you what I've done so far.
Private Sub cboSector_Change()
Dim SQL As String
Dim Sector As String
SQL = "SELECT FirstName, Surname, Title FROM AttendanceArchive WHERE SchoolService = cboSector.Text"
lstOutcome.RowSource = SQL
End Sub
No need to tell you I've tried all variations of the more obvious stuff. Changing, rearranging.. didn't help me. I have the feeling I'm missing something very basic.. or it might not be possible.
I chose this path of doing things, because in my old database (Attendance is now being moved to the new one, thus becoming Archive) I have a similar thing, but input comes from an inputbox. The following statement works perfectly fine in my old database.
Private Sub cmdFind_Click()
Dim sql As String
sql = "SELECT FirstName, Surname, Title FROM Attendance WHERE FirstName = EmployeeName OR Surname = EmployeeName"
lstOutcome.RowSource = sql
End Sub
It's been a while since I used VB, so a bit of a helping hand will be grately appreciated.
Thanks in advance
Last edited: