I Imported tables, queries, forms and reports from another database into a new database. In the new database I created a form that uses a text box that will search for records when entering a contract number. The problem I'm having is that once the command button has been clicked after entering the contract number, I get a type mismatch error.
I have used this same procedure in other projects and it worked just fine, but for some reason I can't get it to work with this particular project. Could the problem have something to do with the fact that I imported from another database?
The following is the source code used in the command button:
Private Sub cmdSearch_Click()
Dim dbs As Database, rst As Recordset
Me.txtSearch.SetFocus
If Me.txtSearch.Text = "" Then
MsgBox "Please enter a Contract Number"
Me.txtSearch.SetFocus
Exit Sub
End If
Set dbs = OpenDatabase("Construction.mdb")
txtSearch.SetFocus
Set rst = dbs.OpenRecordset("Select ContractNo from tblContracts " & " Where ContractNo Like " & "'*" & _
Me.txtSearch & "*'" & ";")
If rst.RecordCount < 1 Then
MsgBox "Construction # invalid or not in database, Please try again", vbOKOnly, "Code Error"
Else
DoCmd.OpenForm "tblContracts", acFormDS, , "ContractNo Like '*" & Forms!Construction_Records.txtSearch & "*'"
Exit Sub
End If
End Sub
I have used this same procedure in other projects and it worked just fine, but for some reason I can't get it to work with this particular project. Could the problem have something to do with the fact that I imported from another database?
The following is the source code used in the command button:
Private Sub cmdSearch_Click()
Dim dbs As Database, rst As Recordset
Me.txtSearch.SetFocus
If Me.txtSearch.Text = "" Then
MsgBox "Please enter a Contract Number"
Me.txtSearch.SetFocus
Exit Sub
End If
Set dbs = OpenDatabase("Construction.mdb")
txtSearch.SetFocus
Set rst = dbs.OpenRecordset("Select ContractNo from tblContracts " & " Where ContractNo Like " & "'*" & _
Me.txtSearch & "*'" & ";")
If rst.RecordCount < 1 Then
MsgBox "Construction # invalid or not in database, Please try again", vbOKOnly, "Code Error"
Else
DoCmd.OpenForm "tblContracts", acFormDS, , "ContractNo Like '*" & Forms!Construction_Records.txtSearch & "*'"
Exit Sub
End If
End Sub