Hi all, I'm hoping someone could help me with an issue I have with a new database I've created.
For now the setup is simple, I have a form with subform. This subform displays a table, the contents of which are altered depending on what you choose in three combo boxes.
I receive the following error when using either cbo_winegrade or cbo_vintage. If I start building the query from the first combobox (cbo_winetype) then everything works OK.
Here's the code:
Thanks very much for any help you can provide.
David
For now the setup is simple, I have a form with subform. This subform displays a table, the contents of which are altered depending on what you choose in three combo boxes.
I receive the following error when using either cbo_winegrade or cbo_vintage. If I start building the query from the first combobox (cbo_winetype) then everything works OK.
Here's the code:
Code:
Option Compare Database
Private Sub but_clearcbos_Click()
Me.cbo_winetype = Null
Me.cbo_winegrade = Null
Me.cbo_vintage = Null
End Sub
Private Sub cbo_winetype_AfterUpdate()
Call SearchCriteria
End Sub
Private Sub cbo_winegrade_AfterUpdate()
Call SearchCriteria
End Sub
Private Sub cbo_vintage_AfterUpdate()
Call SearchCriteria
End Sub
Function SearchCriteria()
Dim MyWineType, strWineGrade, strVintage As String
Dim task, strCriteria As String
If IsNull(Me.cbo_winetype) Then
MyWineType = "[Type] = like '*'"
Else
MyWineType = "[Type] = '" & Me.cbo_winetype & "'"
End If
If IsNull(Me.cbo_winegrade) Then
strWineGrade = "[Grade] like '*'"
Else
strWineGrade = "[Grade] = '" & Me.cbo_winegrade & "'"
End If
If IsNull(Me.cbo_vintage) Then
strVintage = "[Vintage] like '*'"
Else
strVintage = "[Vintage] = '" & Me.cbo_vintage & "'"
End If
strCriteria = MyWineType & "And" & strWineGrade & "And" & strVintage
task = "Select * from tbl_winestock where " & strCriteria
Me.tbl_winestock_subform1.Form.RecordSource = task
Me.tbl_winestock_subform1.Form.Requery
End Function
Thanks very much for any help you can provide.
David