Access VBA OpenRecordset Group Level OutputTo No records error

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
Hi,

I have an issue when my code runs, it only grab the records that the cursor is on and not looping through to grab the specific records grouped by ID....For the 31 clients, ID 48961 which is 1 client of the 31 clients which the cursor was on in the Form was the only records pulled for the 31 different client groups...See Attachment Below...My issue is I'm only pulling records where my cursor is pointing to and not looping through all the records...Thanks

Private Sub cmdSendRpt_Click()
Dim rst As DAO.Recordset
Dim strSql As String

strSql = "Select * FROM Qry_Max_Pymt_PymtEmailDetail;"

Set rst = CurrentDb.OpenRecordset(strSql)

Do While Not rst.EOF

Me.txtID = rst![ID]

DoCmd.OutputTo acOutputQuery, "Max_Pymt_EmailDetails1", acFormatXLS, "C:\Users\amccoy\Desktop\TestFolder" & "\" & rst![ID] & "_" & rst![PymtsPayee] & ".xls"

DoEvents
rst.MoveNext

Loop

rst.Close
Set rst = Nothing

End Sub
 

Attachments

  • Queries.jpg
    Queries.jpg
    127.6 KB · Views: 12
  • GroupbyExport.jpg
    GroupbyExport.jpg
    45.8 KB · Views: 12

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
How do I execute your test code, just drop it in a module and add the valid ID that suppose to loop through the code? I'm a real novice at this...
No just use
TempVars("txtID") = rst!ID then run the second query
 
Upvote 0
I guess the query needs to refer to the tempvar value as well.

Either,
WHERE FieldName = TempVars!MyVal

Or
WHERE FieldName = Eval("TempVars!MyVal")

In other words, you are using tempvars to share data. The code you are writing needs to set the value (on each loop) but the query you wrote needs to read the value (also on each loop - this is a parameter that you need to use to get the data you need on that loop for that ID)
 
Upvote 0
I guess the query needs to refer to the tempvar value as well.

Either,
WHERE FieldName = TempVars!MyVal

Or
WHERE FieldName = Eval("TempVars!MyVal")

In other words, you are using tempvars to share data. The code you are writing needs to set the value (on each loop) but the query you wrote needs to read the value (also on each loop - this is a parameter that you need to use to get the data you need on that loop for that ID)
Well we had this in post #5
Code:
SELECT T_Payment_Details.ID, T_Payment_Details.PymtAmount AS [Total Payment Amount], T_Payment_Details.Pymt_Custodian AS Custodian, T_Payment_Details.PymtMethod AS [Payment Method], T_Payment_Details.PymtsPayee AS [Payee Name], T_Payment_Details.Email
FROM T_Payment_Details
WHERE (((T_Payment_Details.ID)=[TempVars]![txtID]));

but no idea as to what the query looks like now.?
 
Upvote 0
I guess that works. Funny no different if you had a hidden textbox on a form called TempVars. Moral of the story: TempVars is a funny name for a form ;)
 
Upvote 0
Well we had this in post #5
Code:
SELECT T_Payment_Details.ID, T_Payment_Details.PymtAmount AS [Total Payment Amount], T_Payment_Details.Pymt_Custodian AS Custodian, T_Payment_Details.PymtMethod AS [Payment Method], T_Payment_Details.PymtsPayee AS [Payee Name], T_Payment_Details.Email
FROM T_Payment_Details
WHERE (((T_Payment_Details.ID)=[TempVars]![txtID]));

but no idea as to what the query looks like now.?
No just use
TempVars("txtID") = rst!ID then run the second query
Hi welshgasman, I attempted to use TempVars("txtID") = rst!ID which is presenting a error for the "txtID" which is bringing in a Null value, the rst!ID is pulling in the value for the first record 48951
 
Upvote 0
Hi welshgasman, I attempted to use TempVars("txtID") = rst!ID which is presenting an error for the "txtID" which is bringing in a Null value, the rst!ID is pulling in the value for the first record 48951
The Query is the same as in Post #5 and in order to recieve records from that query, I modified the WHERE Clause to:

(((T_Payment_Details.ID)=Like "*" &[TempVars]![txtID] & "*"));
 
Upvote 0
Hi welshgasman, I attempted to use TempVars("txtID") = rst!ID which is presenting a error for the "txtID" which is bringing in a Null value, the rst!ID is pulling in the value for the first record 48951
It is not bringing in Null, it is just not assigning it for some reason :(
What is the error? full description please, not just an error number.

I do not know what to tell you?, the syntax is correct :(
From the immediate window
Code:
tempvars("txtID")=458789
? tempvars("txtID")
458789

tempvars!txtid = "fred"
? tempvars!txtID
fred
 
Upvote 0
It is not bringing in Null, it is just not assigning it for some reason :(
What is the error? full description please, not just an error number.

I do not know what to tell you?, the syntax is correct :(
From the immediate window
Code:
tempvars("txtID")=458789
? tempvars("txtID")
458789

tempvars!txtid = "fred"
? tempvars!txtID
fred
The full error is Run-Time error 32535
TempVars can only store data. They cannot store Objects.
It is not bringing in Null, it is just not assigning it for some reason :(
What is the error? full description please, not just an error number.

I do not know what to tell you?, the syntax is correct :(
From the immediate window
Code:
tempvars("txtID")=458789
? tempvars("txtID")
458789

tempvars!txtid = "fred"
? tempvars!txtID
fred

tempvars("txtID")=48951
? tempvars("txtID")
48951

Came back so I'm not understanding the issue...
 
Upvote 0
Now my tempvars("txtID") = 48959 and rst![ID] 48951 at least it's showing a value but the wrong one...The txtID is showing the last value I tested...
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,227
Members
449,371
Latest member
strawberrish

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top