i'm trying to create a search form for access just like the one explained in faq702-1177 and i'm getting an error that says: Compile error, expected variable or procedure, not module and the error points to this line: AddToWhere [Find1] in the following code: Could someone help me out or tell me were i could download a working version?
Private Sub Command23_Click()
On Error GoTo Err_Command23_Click
Dim MySQL As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
' Initialize SELECT statement.
MySQL = "SELECT * FROM tblInfo WHERE "
' Use values entered in text boxes in form header to create criteria for WHERE clause.
'text box name on form 'Field name in Table 'blank info ' number of times run Add
AddToWhere [Find1], "FName", MyCriteria, ArgCount
AddToWhere [Find2], "LName", MyCriteria, ArgCount
' If no criterion specifed, return all records.
If MyCriteria = "" Then
MyCriteria = "True"
End If
' Create SELECT statement.
MyRecordSource = MySQL & MyCriteria
' Optional Order By clause
If Me![Find1] <> "" Then
MyRecordSource = MySQL & MyCriteria & " ORDER BY FName"
ElseIf Me![Find2] <> "" Then
MyRecordSource = MySQL & MyCriteria & " ORDER BY LName"
Else
MyRecordSource = MySQL & MyCriteria & " ORDER BY FName"
End If
' set record source to Subform
Me!frmResults.Form.RecordSource = MyRecordSource
Exit_Command23_Click:
Exit Sub
Err_Command23_Click:
MsgBox Err.Description
Resume Exit_Command23_Click
End Sub
Private Sub Command23_Click()
On Error GoTo Err_Command23_Click
Dim MySQL As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
' Initialize SELECT statement.
MySQL = "SELECT * FROM tblInfo WHERE "
' Use values entered in text boxes in form header to create criteria for WHERE clause.
'text box name on form 'Field name in Table 'blank info ' number of times run Add
AddToWhere [Find1], "FName", MyCriteria, ArgCount
AddToWhere [Find2], "LName", MyCriteria, ArgCount
' If no criterion specifed, return all records.
If MyCriteria = "" Then
MyCriteria = "True"
End If
' Create SELECT statement.
MyRecordSource = MySQL & MyCriteria
' Optional Order By clause
If Me![Find1] <> "" Then
MyRecordSource = MySQL & MyCriteria & " ORDER BY FName"
ElseIf Me![Find2] <> "" Then
MyRecordSource = MySQL & MyCriteria & " ORDER BY LName"
Else
MyRecordSource = MySQL & MyCriteria & " ORDER BY FName"
End If
' set record source to Subform
Me!frmResults.Form.RecordSource = MyRecordSource
Exit_Command23_Click:
Exit Sub
Err_Command23_Click:
MsgBox Err.Description
Resume Exit_Command23_Click
End Sub