Hello, I hope that someone will be able to help me overcome this snag I have run into creating this access 2010 database. I have a database that users will input information into (IDs, names, etc) via form that I will need to retrieve. The basic purpose of this database is to replace users having to send me physical forms when requesting system access. Once they have filled out the form and submit, I have a report that lists all of the users who have done so along with some basic information. On this report there is a button that, when clicked, I need to take each of the entries and output each one to a separate pdf of a full report I have created and deleted them out of the database. The code that I have for this is as follows:
If I run this code a single time it works perfectly fine. The problem occrurs when it tries to recurs back up to the DoCmd.OpenReport "FullReport", acViewPreview, , "ID = '" & ID & "'". This particular version of the code uses a ‘for’ loop, but I have tried it with a ‘while/until’ loop as well and get the same result. I have also tried not having it close and open the list report and use DoCmd.GoToRecord , , acNext, but all that seemed to accomplish was getting of the same full report and it would only delete the first entry. Any help with this would be greatly appreciated.
Code:
Private Sub OutputPdf_Click()
for i = 1 To DCount("ID", "database")
If Not DCount("ID", "database") = 0 Then
‘opens the full report and limits it to one entry of database
DoCmd.OpenReport "FullReport", acViewPreview, , "ID = '" & ID & "'"
‘outputs full report to pdf on HDD with file name based upon fields in table
DoCmd.OutputTo acOutputReport, "FullReport", acFormatPDF, "C:\...\Desktop\" & LegalName & " - " & [ID] & ".pdf"
DoCmd.SetWarnings off
‘deletes item from table
DoCmd.RunSQL "DELETE * FROM database WHERE ID = '" & ID & "'"
‘closes full report
DoCmd.Close acReport, "FullReport", acSaveNo
‘closes and opens list report to refresh
DoCmd.Close acReport, "ListReport", acSaveNo
DoCmd.OpenReport "ListReport", acViewReport, , , acWindowNormal
End If
Next i
End Sub
If I run this code a single time it works perfectly fine. The problem occrurs when it tries to recurs back up to the DoCmd.OpenReport "FullReport", acViewPreview, , "ID = '" & ID & "'". This particular version of the code uses a ‘for’ loop, but I have tried it with a ‘while/until’ loop as well and get the same result. I have also tried not having it close and open the list report and use DoCmd.GoToRecord , , acNext, but all that seemed to accomplish was getting of the same full report and it would only delete the first entry. Any help with this would be greatly appreciated.