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!

Recordset won't open - Error 3061 2

Status
Not open for further replies.

LouiseJ

Technical User
May 18, 2005
29
GB
Could any please explain why the following isn't working?

It seems to fail on the Where clause of the SQL when attempting to open the recordset. However in debug [Forms]![frmMainBuildBOM]![ProductID] has a value. The code is executed from frmMainBuildBOM - ie the form is open.

Error message reads:
'error 3061 Too few parameters. Expected 1'

Thanks



Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String


strSQL = "SELECT tblConponent.ConponentID, tblConponent.ParentProductID, tblConponent.Quantity, tblProduct.ProductName, tblConponent.Notes " & vbCrLf & _
"FROM tblConponent INNER JOIN tblProduct ON tblConponent.ConponentID = tblProduct.ProductID " & vbCrLf & _
"WHERE (((tblConponent.ParentProductID)= [Forms]![frmMainBuildBOM]![ProductID]));"



Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
 
When building SQL strings in VBA, you need actual values rather than references to a form:

Code:
strSQL = "SELECT tblConponent.ConponentID, " & _
   "tblConponent.ParentProductID, tblConponent.Quantity, " & _
   "tblProduct.ProductName, tblConponent.Notes " & _
"FROM tblConponent INNER JOIN tblProduct " & _
"ON tblConponent.ConponentID = tblProduct.ProductID " & _
"WHERE tblConponent.ParentProductID = " & _
[Forms]![frmMainBuildBOM]![ProductID]

 
So no way round it then?

I need to test if a sub form is showing any records as a user moves through the records of the main form. Any suggestions?

Thanks
 
I need to test if a sub form is showing any records as a user moves through the records of the main form. Any suggestions

Public Function getSubCount(subfrm As Access.Form) As Integer
getSubCount = subfrm.Recordset.RecordCount
End Function
call it from the mainforms on current event
Private Sub Form_Current()
if getSubCount(Me.subFormControl.Form) = 0...
End Sub
 
Sorry I missed that Remou.

Thanks Majp.

I appreciate the help from both of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top