dwsteyl
Technical User
- Nov 5, 2007
- 3
Hi there people!
I'm working in VB 6, using an ADO control to connect to an Access 2000 database. The access database has 4 columns. Each column represents a different year, for ex. "2001", "2002" etc.
At startup a combobox (cboNames) is populated with all the names from only one of these columns.
The reason I can't use the column name directly in the filter is because the user can select which year they want to filter (they do this via another combobox). Therefore it needs to be dynamic, which is the reason for variable strYear (see below).
Code example:
dim strYear as string
strYear = "2002" 'normally assigned via user selection
ado1.recordset.movefirst
do while not ado1.recordset.eof()
cboNames.AddItem strYear
ado1.recordset.movenext
loop
Now I want to filter the recordset, using strYear and cboNames.text and this is where my problem lies.
ado1.Recordset.Filter = "strYear LIKE '" & cboNames.Text & "'"
The program keeps crashing at strYear. It is searching for a column with the name strYear, instead of using it's value to select the appropriate column.
I've changed the syntax more than I can count and I just can't seem to get it right.
Any help would be appreciated!
Thanks
dwsteyl
I'm working in VB 6, using an ADO control to connect to an Access 2000 database. The access database has 4 columns. Each column represents a different year, for ex. "2001", "2002" etc.
At startup a combobox (cboNames) is populated with all the names from only one of these columns.
The reason I can't use the column name directly in the filter is because the user can select which year they want to filter (they do this via another combobox). Therefore it needs to be dynamic, which is the reason for variable strYear (see below).
Code example:
dim strYear as string
strYear = "2002" 'normally assigned via user selection
ado1.recordset.movefirst
do while not ado1.recordset.eof()
cboNames.AddItem strYear
ado1.recordset.movenext
loop
Now I want to filter the recordset, using strYear and cboNames.text and this is where my problem lies.
ado1.Recordset.Filter = "strYear LIKE '" & cboNames.Text & "'"
The program keeps crashing at strYear. It is searching for a column with the name strYear, instead of using it's value to select the appropriate column.
I've changed the syntax more than I can count and I just can't seem to get it right.
Any help would be appreciated!
Thanks
dwsteyl