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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hey all i am new here and need some help with recordset

Status
Not open for further replies.

cornbread001

Programmer
Feb 21, 2008
3
US
i keep getting error 3061 to few parameter expected 1. the query that it makes does show up in my queries and it has the correct row count to it but the darn error is consistant i tried everything please help thanks in advanced here is my code.
Private Sub Tax_GotFocus()
Dim intQty As Integer
Dim dblPrice As Double
Dim dblTotal As Double
Dim oldQryRows As String
Dim strRowCntSql As String
Dim dbCnn As DAO.Database
Dim qdfRC As DAO.QueryDef
Dim rcRC As DAO.Recordset
Dim prQdfRC As DAO.Parameter

oldQryRows = "Rows1"
strRowCntSql = "SELECT Count(Sale_Id) " & _
"FROM Part_Sold " & _
"WHERE Part_Sold.[Sale_Id] = [Forms]![Sales]![Part_Sold]![Sale_Id];"

Set dbCnn = CurrentDb
dbCnn.QueryDefs.Delete oldQryRows
Set qdfRC = dbCnn.CreateQueryDef("Rows1", strRowCntSql)
For Each prQdfRC In qdfRC.Parameters
prQdfRC.Value = Eval(prQdfRC.Name)
Next prQdfRC
'qdf![Forms!Sales!Part_Sold!Sale_Id] = Forms![Sales]![Part_Sold]![Sale_Id]
Set qdfRC = dbCnn.OpenRecordset(strRowCntSql)
Debug.Print qdfRC
Debug.Print strRowCntSql
intQty = Me.Part_Sold![Quantity]
Debug.Print intQty
End Sub
 
Figured it out.... dumb mistake that i over looked here is new code for anyone haveing same prob.
Private Sub Tax_GotFocus()
Dim intQty As Integer
Dim dblPrice As Double
Dim dblTotal As Double
Dim oldQryRows As String
Dim strRowCntSql As String
Dim dbCnn As DAO.Database
Dim qdfRC As DAO.QueryDef
Dim rcRC As DAO.Recordset
Dim prQdfRC As DAO.Parameter
Set dbCnn = CurrentDb
oldQryRows = "Rows1"
dbCnn.QueryDefs.Delete oldQryRows

strRowCntSql = "SELECT Count(Sale_Id) " & _
"FROM Part_Sold " & _
"WHERE Part_Sold.[Sale_Id] = [Forms]![Sales]![Part_Sold]![Sale_Id];"



Set qdfRC = dbCnn.CreateQueryDef("Rows1", strRowCntSql)

qdfRC![Forms!Sales!Part_Sold!Sale_Id] = Forms![Sales]![Part_Sold]![Sale_Id]
Set rcRC = qdfRC.OpenRecordset()'removed variable name
'Debug.Print qdfRC
'Debug.Print strRowCntSql
intQty = rcRC.Fields("Expr1000") 'applied variable with
'value returned from query
Debug.Print intQty
End Sub
 
If your table doesn't hold many records this
Code:
intQty = DCOUNT("*", "Part_Sold", "Sale_Id= " & Me.Sale_Id
may also suit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top