S
Shel
Scenario: The code below allows me to use an unbound form (frmLocateTaxPayer)
with unbound text boxes to open and filter another form (frmTaxPayerInfo)
based on the search criteria entered by the user. The problem I am having is
that I do not want to search the txtTxPrID field with the wildcard parameter
of “likeâ€, instead I want the txtTxPrID field to be = to the criteria
entered. For example: If the user enters 2 in the ID field I want that exact
record to appear, not records including the number 2 (like 12, 20, 32, etc…)
Problem: I get an error when I change the word Like to an = in my code. I am
pretty sure this is because my ID field is a number field and my code is
trying to read it as a string (or something of the like). Unfortunately I
don’t know enough about VBA to even begin to create a solution for this.
Please HELP ïŠ
******************CODE***********************
Private Sub btnOK_Click()
If (Eval("[Forms]![empfrmLocateTaxPayer]![txtTxPrID] Is Null And
[Forms]![empfrmLocateTaxPayer]![txtSSN] Is Null And
[Forms]![empfrmLocateTaxPayer]![txtLName] Is Null")) Then
Beep
MsgBox "Please enter search criteria or click Cancel", vbInformation, "No
Search Criteria"
DoCmd.CancelEvent
Else
Dim strSQL As String
Dim strWhere As String
Dim ctl As Control
'Build the wherecondition to use in the OpenObject method.
If Not IsNull(txtTxPrID) Then
strWhere = strWhere & " AND TxPrID Like " & "'" & txtTxPrID & "*'"
End If
If Not IsNull(txtSSN) Then
strWhere = strWhere & " AND SSN Like " & "'" & txtSSN & "*'"
End If
If Not IsNull(txtLName) Then
strWhere = strWhere & " AND TxPrLName Like " & "'" & txtLName & "*'"
End If
'Trim the leading "AND" strWhere and store the new string in strSQL.
If Not IsNull(strWhere) Then
strSQL = Mid$(strWhere, 6)
End If
'Open Form based on the contents of strSQL.
stDocName = "empfrmTaxPayerInfo"
DoCmd.OpenForm stDocName, , , strSQL
'Set the text boxes back to null.
Clear_Controls:
txtTxPrID = Null
txtSSN = Null
txtLName = Null
End If
End Sub
with unbound text boxes to open and filter another form (frmTaxPayerInfo)
based on the search criteria entered by the user. The problem I am having is
that I do not want to search the txtTxPrID field with the wildcard parameter
of “likeâ€, instead I want the txtTxPrID field to be = to the criteria
entered. For example: If the user enters 2 in the ID field I want that exact
record to appear, not records including the number 2 (like 12, 20, 32, etc…)
Problem: I get an error when I change the word Like to an = in my code. I am
pretty sure this is because my ID field is a number field and my code is
trying to read it as a string (or something of the like). Unfortunately I
don’t know enough about VBA to even begin to create a solution for this.
Please HELP ïŠ
******************CODE***********************
Private Sub btnOK_Click()
If (Eval("[Forms]![empfrmLocateTaxPayer]![txtTxPrID] Is Null And
[Forms]![empfrmLocateTaxPayer]![txtSSN] Is Null And
[Forms]![empfrmLocateTaxPayer]![txtLName] Is Null")) Then
Beep
MsgBox "Please enter search criteria or click Cancel", vbInformation, "No
Search Criteria"
DoCmd.CancelEvent
Else
Dim strSQL As String
Dim strWhere As String
Dim ctl As Control
'Build the wherecondition to use in the OpenObject method.
If Not IsNull(txtTxPrID) Then
strWhere = strWhere & " AND TxPrID Like " & "'" & txtTxPrID & "*'"
End If
If Not IsNull(txtSSN) Then
strWhere = strWhere & " AND SSN Like " & "'" & txtSSN & "*'"
End If
If Not IsNull(txtLName) Then
strWhere = strWhere & " AND TxPrLName Like " & "'" & txtLName & "*'"
End If
'Trim the leading "AND" strWhere and store the new string in strSQL.
If Not IsNull(strWhere) Then
strSQL = Mid$(strWhere, 6)
End If
'Open Form based on the contents of strSQL.
stDocName = "empfrmTaxPayerInfo"
DoCmd.OpenForm stDocName, , , strSQL
'Set the text boxes back to null.
Clear_Controls:
txtTxPrID = Null
txtSSN = Null
txtLName = Null
End If
End Sub