Hello,
I am banging my head against the wall with this problem. BEGGING for your help!
I am working in vba, access 2003. I need to run a parameter query on a loop with a new parameter at each iteration of the loop, store the result of each iteration in a temporary table called CumulativePS, and then paste the entire contents of the table in an excel workbook, wb. At the end of the loop, the CumulativePS table should have 35 records (checked this- it works). When I run the simple line 'Select * from CumulativePS;' from a stored query, it gives me the right results. HOWEVER, when I do the following code, only one record (it's the last added record every time) gets selected and pasted into excel:
Where am I going wrong? Is this my error, or does it seem like a sign of some kind of corruption? Incidentally, I should say that this 'select from table and paste into an excel sheet' method is used multiple times in this same module, and it works for all other sheets- the right records get selected and pasted. But for some reason, it is throwing this at me at this point.
Please let me know if pasting more code here would be helpful in figuring out what the problem is. I appreciate all help in advance!
I am banging my head against the wall with this problem. BEGGING for your help!
I am working in vba, access 2003. I need to run a parameter query on a loop with a new parameter at each iteration of the loop, store the result of each iteration in a temporary table called CumulativePS, and then paste the entire contents of the table in an excel workbook, wb. At the end of the loop, the CumulativePS table should have 35 records (checked this- it works). When I run the simple line 'Select * from CumulativePS;' from a stored query, it gives me the right results. HOWEVER, when I do the following code, only one record (it's the last added record every time) gets selected and pasted into excel:
PHP:
'PASTE into cumulative sheet:
'-------
' Tried putting in a sql string directly in vb, but didn't work:
'Dim sql_cum_paste As String
'sql_cum_paste = "Select * from CumulativePS;"
'---------
Dim rs_cum_paste_qdf As QueryDef
Set rs_cum_paste_qdf = dbs.QueryDefs!CumulativePS_selectall
Dim rs_cum_paste As DAO.Recordset
Set rs_cum_paste = rs_cum_paste_qdf.OpenRecordset
'debugger prints '1':
Debug.Print rs_cum_paste.RecordCount
Dim lastrowcumreg As Long
Dim cum_reg_recordcount As Long
If Not (rs_cum_paste.EOF = True And rs_cum_paste.BOF = True) Then
rs_cum_paste.MoveLast
cum_reg_recordcount = rs_cum_paste.RecordCount
lastrowcumreg = header_cumreg + cum_reg_recordcount + 1
wb.Sheets("CumulativeSummary").Range(namecol & header_cumreg + 1).CopyFromRecordset rs_cum_paste
Else
GoTo exitcumreg
End If
Where am I going wrong? Is this my error, or does it seem like a sign of some kind of corruption? Incidentally, I should say that this 'select from table and paste into an excel sheet' method is used multiple times in this same module, and it works for all other sheets- the right records get selected and pasted. But for some reason, it is throwing this at me at this point.
Please let me know if pasting more code here would be helpful in figuring out what the problem is. I appreciate all help in advance!