Nested recordset reads

tim564

New member
Local time
Today, 05:10
Joined
Jul 6, 2012
Messages
6
Hi guys

I'm trying to process records from a table based on the unique value of one field but my code fails at the last line shown below "Set rst2..." :

What am I doing wrong??

Public Function UpdatePrimary()
Dim db As DAO.Database

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset

Dim strSQL1 As String
Dim strSQL2 As String




Set db = CurrentDb()

strSQL1 = "SELECT customer FROM Global_Sold_To GROUP BY customer"
Set rst1 = db.OpenRecordset(strSQL1)
rst1.MoveFirst

Do While Not rst1.EOF

strSQL2 = "SELECT sales_office, industry, distribution_channel, primary_owner FROM Global_Sold_To WHERE customer = rstunique!customer;"
Set rst2 = db.OpenRecordset(strSQL2)
rst2.MoveFirst...


The error I get is Run time error '3061' Too few parameters expected.

thanks

Tim
 
strSQL2 = "SELECT sales_office, industry, distribution_channel, primary_owner FROM Global_Sold_To WHERE customer = rstunique!customer;"
This is what you're doing wrong. Your value is not in scope.

Why are you doing this in a recordset anyway? Why not do it in a query?
 
I noticed my error, Im new to this but the reason for using a function comes later in the code, but your right a query would have been easier for this part.
 
If you're in doubt, ask one of us. You probably don't need a function.

Happy developing!
 

Users who are viewing this thread

Back
Top Bottom