Can't get query to close before looping to requery | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| |
Hi there,
I'm woking on a function that takes the input from a form (including Payroll Contact), uses it as a query parameter, runs the query, and then emaills out a custom .xls file using the sendObject method to the Payroll Contact specified in a list.
After perfroming this function it loops to the next [PayrollContact]person on the list and requeries to send them a custom list. The problem: After sending the first list the first query will not close causing the same list to be sent to each of the PayrollContacts in individual emails.
If I can get the query to close and reopen after I've moved to the next record it should refresh itself with the correct data.
Any ideas on what's wrong with my code? All help is greatly apprecated. (I'm using Access 2003 on XP) - Public Function SendEMail()
-
Dim rs As DAO.Recordset
-
Dim strEmailRec As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM MailList")
-
Do While Not rs.EOF
-
-
'Set the contents of the email
-
strEmailRec = rs.Fields("[EmailAddress]").Value
-
strSubject = "Q3 2007 eIP - Payout File - " & rs.Fields("[WorkLocation]").Value & " " & rs.Fields("[PA]").Value
-
strMessageText = "Hi " & rs.Fields("[PayrollContact]").Value & "," & vbNewLine & vbNewLine & "Please find attached the Q3 eIP Payout File to be processed with your November 2007 payroll." & vbNewLine & vbNewLine & "The Total Payout Amounts to be paid out are in column BP." & vbNewLine & "The Payout Currency is in column BO." & vbNewLine & vbNewLine & "Please let me know if you have any questions." & vbNewLine & vbNewLine & "Best regards,"
-
-
'Send the e-mail with the spreadsheet attached. Change TRUE to FALSE if you don't want to review the e-mail
-
DoCmd.SendObject acQuery, "qryLocationCut", acFormatXLS, strEmailRec, "", "", strSubject, strMessageText, True, ""
-
-
'Close the currently open query
-
DoCmd.Close acQuery, "qryLocationCut", acSaveNo
-
-
rs.MoveNext
-
-
'Open the control panel form and advance to the next record
-
DoCmd.OpenForm "frmControlPanel", acNormal
-
DoCmd.GoToRecord acActiveDataObject, "frmControlPanel", acNext
-
'open the location cut query based on the next record.
-
DoCmd.OpenQuery "qryLocationCut", acViewNormal, acEdit
-
-
-
Loop
-
End Function
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery
Instead of the DoCmd query manipulation I would use a "template" query e.g. named qryLocationCutTemplate like:
select * from tblX where WorkLocation = '$WorkLocation$')
In the code I would use: -
dim qdT as DAO.QueryDef ' Make sure you have a reference set to the DAO library
-
dim qd as DAO.QueryDef
-
-
set qdT=currentdb.querydefs("qryLocationCutTemplate")
-
set qd=currentdb.querydefs("qryLocationCut")
-
-
' Now in the loop use before executing the SendEmail:
-
qd.SQL = Replace(qdT.SQL,'$WorkLocation$',rs!WorkLocation)
-
Getting the idea ?
Nic;o)
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
Can you explain more about using the template? I'm not sure I get it after all...
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery
Try: -
qd.SQL = Replace(qdT.SQL,"$WorkLocation$",rs!WorkLocation)
-
The template is needed to make sure the part to replace ($WorkLocation$) is "stable". After updating the $WorkLocation$ in qd, the next time the location needs to be replaced you would need to know the previously entered location...
Nic;o)
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery Quote:
Originally Posted by raddrummer Can you explain more about using the template? I'm not sure I get it after all... This would be a query in your database that is simply used for making copies from. A "Template" query.
What you do is : - Design and save the template query (one off).
- For each use :
- Copy the template query to a new / temporary query.
- Update the SQL with your own modified SQL.
- Run it.
- Delete it.
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
Thanks NeoPa,
I'm playing with this but still getting an error message saying that a dialog box is open on line 30.
any ideas???? -
-
Public Function SendEMail()
-
Dim rs As DAO.Recordset
-
Dim strEmailRec As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
Dim qdT As DAO.QueryDef ' Make sure you have a reference set to the DAO library
-
Dim qd As DAO.QueryDef
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PayrollContacts")
-
Set qdT = CurrentDb.QueryDefs("qryLocationCutTemplate") 'Master Template
-
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary") 'Master Template copies itself to this query and replaces criteria based on current record.
-
-
Do While Not rs.EOF
-
-
'Create a copy of the template called qryLocationCutTemporary
-
DoCmd.CopyObject , "qryLocationCutTemporary", acQuery, "qryLocationCutTemplate"
-
-
'Replace SQL with that from current record
-
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qdT.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qdT.SQL, "$PayrollContact$", rs!PayrollContact)
-
-
-
-
'Set the contents of the email
-
strEmailRec = rs.Fields("[EmailAddress]").Value
-
strSubject = "Q3 2007 eIP - Payout File - " & rs.Fields("[WorkLocation]").Value & " " & rs.Fields("[PA]").Value
-
strMessageText = "Hi " & rs.Fields("[PayrollContact]").Value & "," & vbNewLine & vbNewLine & "Please find attached the Q3 eIP Payout File to be processed with your November 2007 payroll." & vbNewLine & vbNewLine & "The Total Payout Amounts to be paid out are in column BP." & vbNewLine & "The Payout Currency is in column BO." & vbNewLine & vbNewLine & "Please let me know if you have any questions." & vbNewLine & vbNewLine & "Best regards,"
-
-
'Send the e-mail with the spreadsheet attached. Change TRUE to FALSE if you don't want to review the e-mail
-
DoCmd.SendObject acQuery, "qryLocationCutTemporary", acFormatXLS, strEmailRec, "", "", strSubject, strMessageText, True, ""
-
-
'Close the currently open query
-
DoCmd.DeleteObject acQuery, "qryLocationCutTemporary"
-
-
rs.MoveNext
-
-
-
-
Loop
-
End Function
-
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery
Let me see if I can see anything when I get home with a bit more time available...
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery
Rad,
I like some of your code. There are some tidy ideas in there.
I've made some small sugested changes and my comments (only to stand out from yours) start at the left.
It's never a good idea to change (or recreate) an object while there is a pointer to it currently active (qd), so I moved the Set into the loop AFTER the copy. Similarly, deleting an item that is currently in a pointer (referenced) is not a good idea.
I'm not sure this will fix your particular problem though, as that seems to be connected with a dialog box remaining open. Possibly due to the [EditMessage] parameter being set to TRUE in your call. I don't know for sure. Try this anyway, perhaps the problem will have sorted itself out in the wash. - Public Function SendEMail()
-
Dim rs As DAO.Recordset
-
Dim strEmailRec As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
Dim qdT As DAO.QueryDef ' Make sure you have a reference set to the DAO library
-
Dim qd As DAO.QueryDef
-
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PayrollContacts")
-
Set qdT = CurrentDb.QueryDefs("qryLocationCutTemplate") 'Master Template
-
-
Do While Not rs.EOF
-
-
'Create a copy of the template called qryLocationCutTemporary
-
DoCmd.CopyObject , "qryLocationCutTemporary", acQuery, "qryLocationCutTemplate"
-
'Line moved into the loop to run after object created.
-
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary") 'Master Template copies itself to this query and replaces criteria based on current record.
-
-
'Replace SQL with that from current record
-
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qdT.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qdT.SQL, "$PayrollContact$", rs!PayrollContact)
-
-
-
-
'Set the contents of the email
-
strEmailRec = rs.Fields("[EmailAddress]").Value
-
strSubject = "Q3 2007 eIP - Payout File - " & rs.Fields("[WorkLocation]").Value & " " & rs.Fields("[PA]").Value
-
strMessageText = "Hi " & rs.Fields("[PayrollContact]").Value & "," & vbNewLine & vbNewLine & "Please find attached the Q3 eIP Payout File to be processed with your November 2007 payroll." & vbNewLine & vbNewLine & "The Total Payout Amounts to be paid out are in column BP." & vbNewLine & "The Payout Currency is in column BO." & vbNewLine & vbNewLine & "Please let me know if you have any questions." & vbNewLine & vbNewLine & "Best regards,"
-
-
'Send the e-mail with the spreadsheet attached. Change TRUE to FALSE if you don't want to review the e-mail
-
DoCmd.SendObject acQuery, "qryLocationCutTemporary", acFormatXLS, strEmailRec, "", "", strSubject, strMessageText, True, ""
-
'Finish with qd before deleting temp query
-
Set qd = Nothing
-
-
'Close the currently open query
-
'Delete the temp query
-
DoCmd.DeleteObject acQuery, "qryLocationCutTemporary"
-
-
rs.MoveNext
-
-
-
-
Loop
-
End Function
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery
Hmm, it would be easier to save a qryDummy for the processing and use: -
dim qd as dao.querydef
-
dim qdT as dao.querydef
-
-
set qd = currentdb.querydefs("qryOriginal")
-
set qdT = currentdb.querydefs("qryDummy")
-
-
qdT = replace(qd.SQL,"[string to replace]","[string new]")
-
' place here the needed command with the qryDummy
-
The query "qryDummy" can be used directly after the replace.
Nic;o)
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
Alright, I'm officially frustrated now. The replace method isn't taking and I;m ending up with the entire (unfiltered) ataset as an attachement for all emails.
I am having success getting the recordset to advance when adressing the individual emails though.
I thought maybe tying the recordset to a form and then advancing to the next record in the form and passing the parameters of the current record through to the query might help things but it doesn't....so I'm back to square one.
Any help getting the query to work properly would be most appreciated!!
Thanks! -
Public Function SendEMail()
-
Dim rs As DAO.Recordset
-
Dim strEmailRec As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
Dim qd As DAO.QueryDef 'This is the original "Master" query
-
Dim qdT As DAO.QueryDef 'This is the copy of the original for each use
-
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PayrollContacts")
-
Set qdT = CurrentDb.QueryDefs("qryLocationCutTemplate") 'Master query
-
-
-
Do While Not rs.EOF
-
-
'Create a copy of the template called qryLocationCutTemporary
-
DoCmd.CopyObject , "qryLocationCutTemporary", acQuery, "qryLocationCutTemplate"
-
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary") 'Master query copies itself to this query_
-
'and replaces criteria based on current record.
-
-
-
-
'Replace SQL with that from current record
-
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qdT.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qdT.SQL, "$PayrollContact$", rs!PayrollContact)
-
DoCmd.OpenQuery "qryLocationCutTemporary", acViewNormal, acEdit
-
-
-
'Set the contents of the email
-
strEmailRec = rs.Fields("[EmailAddress]").Value
-
strSubject = "Q3 2007 eIP - Payout File - " & rs.Fields("[WorkLocation]").Value & " " & rs.Fields("[PA]").Value
-
strMessageText = "Hi " & rs.Fields("[PayrollContact]").Value & "," & vbNewLine & vbNewLine & "Please find attached the Q3 eIP Payout File to be processed with your November 2007 payroll." & vbNewLine & vbNewLine & "The Total Payout Amounts to be paid out are in column BP." & vbNewLine & "The Payout Currency is in column BO." & vbNewLine & vbNewLine & "Please let me know if you have any questions." & vbNewLine & vbNewLine & "Best regards,"
-
-
'Send the e-mail with the spreadsheet attached. Change TRUE to FALSE if you don't want to review the e-mail
-
DoCmd.SendObject acQuery, "qryLocationCutTemporary", acFormatXLS, strEmailRec, "", "", strSubject, strMessageText, True
-
-
'Finish with qd before deleting temp query
-
Set qd = Nothing
-
-
-
-
'Close the currently open query
-
DoCmd.Close acQuery, "qryLocationCutTemporary"
-
DoCmd.DeleteObject acQuery, "qryLocationCutTemporary"
-
-
rs.MoveNext
-
DoCmd.OpenForm "frmpayrollcontacts", acNormal
-
DoCmd.GoToRecord acDataForm, "PayrollContact", acNext
-
-
Loop
-
End Function
-
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery Quote:
Originally Posted by nico5038 Hmm, it would be easier to save a qryDummy for the processing and use: -
dim qd as dao.querydef
-
dim qdT as dao.querydef
-
-
set qd = currentdb.querydefs("qryOriginal")
-
set qdT = currentdb.querydefs("qryDummy")
-
-
qdT = replace(qd.SQL,"[string to replace]","[string new]")
-
' place here the needed command with the qryDummy
-
The query "qryDummy" can be used directly after the replace.
Nic;o) Correct me if I'm wrong Nico, but you're saying here that copying and deleting the temp query for every iteration is wasted time and effort. If so, then I agree completely. I wasn't focused on optimising at that stage ;) (My excuse & I'm sticking to it).
I'm also assuming you meant line #7 to read : - qdT.SQL = Replace(qd.SQL,"[string to replace]","[string new]")
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery
@raddrummer - I'm not ignoring you but your explanation is not too clear (no useful details I could see) so I will need to spend more time to understand what you're trying to say. This will have to wait until I get home when I can check again with a more relaxed timeframe.
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
OK, thanks NEoPa. Let me know what details you need and I'd be happy to post them.
Rad
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery
Well Rad, it would be considerate to actually post what it is you've tried (not the code - that's simply a request for me to go to all the trouble of working out what's what by parsing your code) and what did and did not work. If an issue is fixed then you pass that on clearly to save me the effort of reading through the whole thread again to work out where we are. Posting code is not bad in itself, but if you use it to save yourself the trouble of explaining what you changed and what effect that has had on your project, then you will appreciate that working on your problem is going to be even harder than if you communicate clearly. It's always important to know whether or not you've taken any of the previous suggestions on board. Otherwise it's like trying to having a conversation with a mute person - frustrating and nonprogressive.
For instance, I had to read through all of your code to notice that you'd added in new lines at #26 & #43. The only effect I would expect this to have is to stop some of the processing working as the query should not be open during this process at all as far as I can see.
If all this sounds really heavy then I'm sorry, and I'm certainly not trying to flame or insult you. I just don't know any way of getting the point across without it.
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery Quote:
Originally Posted by NeoPa Correct me if I'm wrong Nico, but you're saying here that copying and deleting the temp query for every iteration is wasted time and effort. If so, then I agree completely. I wasn't focused on optimising at that stage ;) (My excuse & I'm sticking to it).
I'm also assuming you meant line #7 to read : - qdT.SQL = Replace(qd.SQL,"[string to replace]","[string new]")
It's not "better", but giving the same result and personally I prefer as little as code as necessary.
Your posted code: -
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qdT.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qdT.SQL, "$PayrollContact$", rs!PayrollContact)
-
won't work as you're replacing only one field and place it into qd.SQL
It shold look like: -
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qd.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qd.SQL, "$PayrollContact$", rs!PayrollContact)
-
The qdT.SQL should only be used "initially", then continue with the qd.SQL !
Best to place a breakpoint in the code and use F8 to singlestep through the code to see what's happening. In the immediate window you can type:
?qd.SQL
and press enter to see the result. A great way to see that code is working as expected (or not :-)
Getting the idea ?
Nic;o)
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery Quote:
Originally Posted by nico5038 It's not "better", but giving the same result and personally I prefer as little as code as necessary. I'm not sure if I understand you correctly Nico :S
Are you saying line #7 was as you wanted it? If so that was certainly something I wasn't aware of (I suppose the .SQL property is the default).
Certainly your other point was a good one and is definitely to be recommended (IE. Not copying the QueryDef every time through the loop). Quote:
Originally Posted by nico5038 Your posted code: -
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qdT.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qdT.SQL, "$PayrollContact$", rs!PayrollContact)
-
won't work as you're replacing only one field and place it into qd.SQL
It shold look like: -
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qd.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qd.SQL, "$PayrollContact$", rs!PayrollContact)
-
The qdT.SQL should only be used "initially", then continue with the qd.SQL ! Good spot. That will certainly be causing issues for Rad. Quote:
Originally Posted by nico5038 Best to place a breakpoint in the code and use F8 to singlestep through the code to see what's happening. In the immediate window you can type:
?qd.SQL
and press enter to see the result. A great way to see that code is working as expected (or not :-)
Getting the idea ?
Nic;o) There is an article ( Debugging in VBA) that may help with this.
Hope this helps.
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
Oh boy...
1. OK, so does
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary")
get placed in before the loop starts? If so then I get an error stating that the object could not be found as I don't create it from the template until the loop starts.
when I tried placing
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary")
inside the loop I got an error message saying that the object already exists and would I like to create it anyway.
2. The criteria for the PA, WorkLocation, and PayrollContacts fields in my queries (qryLocationCutTemplate and qryLocationCutTemporary) use the [PayrollContacts]![PayrollContact] , etc. naming convention to point to the current record in my PayrollContacts Table. I expected the query to pull the values from the current record in PayrollContacts in as criteria, however these aren't filtering at all as I keep getting the entire record set back. Any suggestions here?
Below is a chunk of the current version of the code.
I've moved the query definition back out of the loop to line 11 and have also changed lines 24 and 25 per Nico's suggestion. -
Public Function SendEMail()
-
Dim rs As DAO.Recordset
-
Dim strEmailRec As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
Dim qd As DAO.QueryDef 'This is the original "Master" query
-
Dim qdT As DAO.QueryDef 'This is the copy of the original for each use
-
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PayrollContacts")
-
Set qdT = CurrentDb.QueryDefs("qryLocationCutTemplate") 'Master query
-
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary") 'Master query copies itself to this query_
-
'and replaces criteria based on current record.
-
-
-
Do While Not rs.EOF
-
-
'Create a copy of the template called qryLocationCutTemporary
-
DoCmd.CopyObject , "qryLocationCutTemporary", acQuery, "qryLocationCutTemplate"
-
-
-
-
'Replace SQL with that from current record
-
qd.SQL = Replace(qdT.SQL, "$PA$", rs!PA)
-
qd.SQL = Replace(qd.SQL, "$WorkLocation$", rs!WorkLocation)
-
qd.SQL = Replace(qd.SQL, "$PayrollContact$", rs!PayrollContact)
-
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery
1) Make sure "qryLocationCutTemporary" does exist as a "saved" query in your database.
2) drop the "DoCmd.CopyObject " line and give it a try.
Nic;o)
| | Newbie | | Join Date: Oct 2007 Location: Bay Area, CA
Posts: 26
| | | re: Can't get query to close before looping to requery
Now I'm getting the Enter Parameter Value msgbox looking for the values of PayrollContacts!PayrollContact, etc.....
Ist seems like the values from the current record in the record set are not being passed into the query...
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Can't get query to close before looping to requery Quote:
Originally Posted by raddrummer Now I'm getting the Enter Parameter Value msgbox looking for the values of PayrollContacts!PayrollContact, etc.....
Ist seems like the values from the current record in the record set are not being passed into the query... This implies that fieldnames aren't matching with the table/query.
Use the breakpoint and F8 to investigate the contents of the qd.SQL string.
Nic;o)
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,730
| | | re: Can't get query to close before looping to requery
First of all, my answers may differ from Nico's but each should work. We just have a slightly different approach and you can simply pick and choose which you prefer. Quote:
Originally Posted by raddrummer Oh boy...
1. OK, so does
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary")
get placed in before the loop starts? If so then I get an error stating that the object could not be found as I don't create it from the template until the loop starts.
when I tried placing
Set qd = CurrentDb.QueryDefs("qryLocationCutTemporary")
inside the loop I got an error message saying that the object already exists and would I like to create it anyway. I would have the CopyObject outside of and before the loop, and a DeleteObject outside of and after the loop. Having a dummy QueryDef left around in your database permanently for all such occasions is another way to approach this if you prefer (Nico's way). Quote:
Originally Posted by raddrummer 2. The criteria for the PA, WorkLocation, and PayrollContacts fields in my queries (qryLocationCutTemplate and qryLocationCutTemporary) use the [PayrollContacts]![PayrollContact] , etc. naming convention to point to the current record in my PayrollContacts Table. I expected the query to pull the values from the current record in PayrollContacts in as criteria, however these aren't filtering at all as I keep getting the entire record set back. Any suggestions here? How complicated is the SQL from your template query? It may be worth posting that here (we can't comment much on this without seeing that). The replaces should work now but they obviously depend on the original SQL including the correct words to replace.
Try adding the following line in the code most recently displayed (post #17) after line #25 : - Debug.Print "qdT = " & qdT.SQL & vbCRLF & _
-
"qd = " & qd.SQL & vbCRLF & _
-
"PA = " & rs!PA & vbCRLF & _
-
"WL = " & rs!WorkLocation & vbCRLF & _
-
"PC = " & rs!PayrollContact
Hopefully, the results will be illuminating.
|  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|