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
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