Why does this code not work?

G

Guest

I have been trying to work out why this code doesn't work and can't. I admit
to being a bit rusty!!n I use Query Defs because I find them easier than
ordinary SQL statements with all their puncutations. Can anyone help, thanks:

strSQL = "SELECT * From qryInvoicePayerIDS;"
Set qdf2 = CurrentDb.CreateQueryDef("", strSQL)
Set rstPayer = qdf2.OpenRecordset

With rstPayer
If Not .EOF Then
.MoveFirst
End If
Do Until .EOF
strInvoicePayer = rstPayer!invoicecontact

'Now get the contact ids the invoice payer is paying for, including himself

strSQL = "PARAMETERS [parContact] Text; "
strSQL = strSQL & "SELECT * From qryInvoicedSubsNoDiscounts WHERE
InvoiceContact = [parContact];"
Set qdf4 = CurrentDb.CreateQueryDef("", strSQL)
qdf4.Parameters("parContact") = strInvoicePayer
Set rstPatientsOnPlan = qdf4.OpenRecordset


rstPatientsOnPlan.MoveFirst
rstPatientsOnPlan.MoveLast
'Count how many are being paid for
intPayees = rstPatientsOnPlan.recordCount
rstPatientsOnPlan.MoveFirst


If Not rstPatientsOnPlan.EOF Then
.MoveFirst
End If
Do Until rstPatientsOnPlan.EOF


strSQL = "SELECT * From
tblMembershipReport;"
Set qdf =
CurrentDb.CreateQueryDef("", strSQL)
Set rstMembershipReport =
qdf.OpenRecordset
rstMembershipReport.AddNew

rstMembershipReport!InvoicePayerID =
strInvoicePayer
rstMembershipReport!PaidForID =
rstPatientsOnPlan!ContactID
rstMembershipReport.Update

rstPatientsOnPlan.MoveNext
Loop



.MoveNext
Loop
End With


Paul
 
T

TC

Paul, there's no point saying that you code "does not work", unless you
tell us what is happening, from your viewpoint, to make you /say/ it
does not work.

Does it get an error? If so, what is the message & what line of code
does it happen on? Or does the code do nothing? Or does it hang in an
infinite loop? Or produce the wrong result at line #123? Or - what?

Here are some tips to help you ask your questions effectively:
http://tc2.atspace.com/0012-UsingUsenet.htm#PostBody

HTH,
TC (MVP Access)
http://tc2.atspace.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How do I speed it up 5
CODE not working 4
checking .bof and .eof for empty recordset? 4
can't find strSQL 1
query on query 1
Compile Error ?? 2
VBA Code Help 3
Insert into loop not working 3

Top