Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help debuging this opening form code

Status
Not open for further replies.

WallT

Vendor
Aug 13, 2002
247
US
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
 
DavL

Have you tried your query expression without the single quotes around the OrderNumber in your query??

Binky ::)
><>
 
Okay, that opens the form without an error now, but isn't opening the form with the &quot;OrderNumber&quot; already in place as if doing OpenArgs method. That was my goal.
 
You know, I have tried the OpenArgs method and it still doesn't work. I am starting to think that it is my relationship. The these are two separate tables with the primary key being {OrderNumber} in both of them which makes their relationship a ONE TO ONE. Both are Long Integer, the Orders Table is AutoNumber, but the Direct Billing Table is just Number. Do you think this has anything to do with it, or do I have a property setting that I am missing that needs to be changed?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top