I am trying to open a form "Direct Billing Form" from a command button on my "Work Order" form. The direct billing form comes from a table "TBLDirectBilling" where the primary key is [OrderNumber]. The "Work Order" form comes from a table "TBLOrders" where the primary key is also [OrderNumber], and they are related via a ONE TO ONE RELATIONSHIP, however I use a query for the form called "New Orders Query". I want to open the form, look for records, if no records, then I want to add a record. Can somebody tell me where I am going wrong with this code. The way it is I am receiving the following error: DATA TYPE MISMATCH IN CRITERIA EXPRESSION. Here is the code...
Private Sub DirectBill_Click()
On Error GoTo Err_DirectBill_Click
Dim MyDb As Database, MyRst As Recordset, Recs As Integer, SQLString As String
Dim stDocName As String, stLinkCriteria As String
Set MyDb = CurrentDb
SQLString = "SELECT Count(*) AS RECORDS FROM TBLOrders WHERE (((TBLOrders.OrderNumber)='" & Me![OrderNumber] & "'));"
Set MyRst = MyDb.OpenRecordset(SQLString, dbOpenDynaset)
MyRst.MoveFirst
Recs = MyRst!records
MyRst.Close
Set MyDb = Nothing
stDocName = "Direct Billing Form"
If Recs > 0 Then
stLinkCriteria = "[OrderNumber]=" & "'" & Me![OrderNumber] & "'"
Screen.PreviousControl.SetFocus
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
End If
Exit_DirectBill_Click:
Exit Sub
Err_DirectBill_Click:
MsgBox Err.Description
Resume Exit_DirectBill_Click
End Sub
Private Sub DirectBill_Click()
On Error GoTo Err_DirectBill_Click
Dim MyDb As Database, MyRst As Recordset, Recs As Integer, SQLString As String
Dim stDocName As String, stLinkCriteria As String
Set MyDb = CurrentDb
SQLString = "SELECT Count(*) AS RECORDS FROM TBLOrders WHERE (((TBLOrders.OrderNumber)='" & Me![OrderNumber] & "'));"
Set MyRst = MyDb.OpenRecordset(SQLString, dbOpenDynaset)
MyRst.MoveFirst
Recs = MyRst!records
MyRst.Close
Set MyDb = Nothing
stDocName = "Direct Billing Form"
If Recs > 0 Then
stLinkCriteria = "[OrderNumber]=" & "'" & Me![OrderNumber] & "'"
Screen.PreviousControl.SetFocus
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
End If
Exit_DirectBill_Click:
Exit Sub
Err_DirectBill_Click:
MsgBox Err.Description
Resume Exit_DirectBill_Click
End Sub