Runtime Error 3061 Expected 3 (1 Viewer)

mailman26

New member
Local time
Yesterday, 18:43
Joined
Mar 13, 2012
Messages
8
I am trying to run a vba procedure. I am unable to because i get a runtime error 3061 expected 3. Here is the code with the problem. The coloured line is what needs to be debugged.


Set rs = cts.OpenRecordset(qry, dbOpenDynaset)
Do While Not rs.EOF
RawMaterial = rs!Product_Weight_lbs


rs.MoveNext
Loop

rs.Close


Any suggestions and assistance is much appreciated!
 

mailman26

New member
Local time
Yesterday, 18:43
Joined
Mar 13, 2012
Messages
8
qry is a variablw
 

mailman26

New member
Local time
Yesterday, 18:43
Joined
Mar 13, 2012
Messages
8
I tried to concatenate the form references. I still get the same error. Here is the variable and the form references.


'Retrieves the rawMaterial amount in the Stageing table that is associated with the values being currently entered
'And storing it in the variable RawMaterial
ProductionDate.SetFocus
qry = "Select Product_Weight_lbs From tbl_Stageing Where Production_Date = " & ProductionDate.Text

StageID.SetFocus
qry = qry & " and Stage_ID = " & StageID.Text

ProductCondition.SetFocus
qry = qry & " and Product_Condition = " & ProductCondition.Text

ProductCategory.SetFocus
qry = qry & " and Product_Category = " & ProductCategory.Text

TrailerID.SetFocus
qry = qry & " and Trailer_ID = " & TrailerID.Text

EmployeeID.SetFocus
qry = qry & "and Employee_ID = " & EmployeeID.Text

Set rs = cts.OpenRecordset(qry, dbOpenDynaset)
Do While Not rs.EOF
RawMaterial = rs!Product_Weight_lbs
 

MSAccessRookie

AWF VIP
Local time
Yesterday, 21:43
Joined
May 2, 2008
Messages
3,428
I tried to concatenate the form references. I still get the same error. Here is the variable and the form references.


'Retrieves the rawMaterial amount in the Stageing table that is associated with the values being currently entered
'And storing it in the variable RawMaterial
ProductionDate.SetFocus
qry = "Select Product_Weight_lbs From tbl_Stageing Where Production_Date = " & ProductionDate.Text

StageID.SetFocus
qry = qry & " and Stage_ID = " & StageID.Text

ProductCondition.SetFocus
qry = qry & " and Product_Condition = " & ProductCondition.Text

ProductCategory.SetFocus
qry = qry & " and Product_Category = " & ProductCategory.Text

TrailerID.SetFocus
qry = qry & " and Trailer_ID = " & TrailerID.Text

EmployeeID.SetFocus
qry = qry & "and Employee_ID = " & EmployeeID.Text

Set rs = cts.OpenRecordset(qry, dbOpenDynaset)
Do While Not rs.EOF
RawMaterial = rs!Product_Weight_lbs

Without any additional information, the following information would normally be made regarding the DataTypes of Fields in your Query:

Production_Date: Date/Time
Stage_ID: Number
ProductCondition: Text
ProductCategory: Text
TrailerID: Number
EmployeeID: Number

Your Text Fields are not formatted like they are Text Fields, and there is no gaurantee that they will work. Text Fields need to be Surrounded by Quotes:

(qry = qry & " and Trailer_ID = '" & TrailerID.Text & "'").
 
Last edited:

Users who are viewing this thread

Top Bottom