Link to home
Start Free TrialLog in
Avatar of Jack Marley
Jack Marley

asked on

MS Access Save as File

Hi,

I have an Access Database  with a form that will print selected reports by group. Which it does fine. But I want the saved file to have the field InvoiceNum in the file name.

Each file includes the correct "Account" field, but every file has the same "InvoiceNum" field in the filename - not the one in he individual report.

I was wondering whether anyone could see why his might be happening?? :S

Private Sub Report_Open(Cancel As Integer)
If Len(strRptFilter) <> 0 Then
     Me.Filter = strRptFilter
     Me.FilterOn = True
End If
End Sub

Private Sub Report_Close()
strRptFilter = vbNullString

End Sub


Private Sub Command2_Click()

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Account] FROM [InvoiceDetail Query1] ORDER BY [Account];", dbOpenSnapshot)
Set rst2 = CurrentDb.OpenRecordset("SELECT DISTINCT [InvoiceNum] FROM [InvoiceDetail Query1] ORDER BY [InvoiceNum];", dbOpenSnapshot)

Do While Not rst.EOF
    strRptFilter = "[Account] = " & Chr(34) & rst![Account] & Chr(34)

    DoCmd.OutputTo acOutputReport, "InvTotal", acFormatPDF, "C:\Scripts" & "\" & rst![Account] & " - " & rst2![InvoiceNum] & ".pdf"
    DoEvents
    rst.MoveNext
Loop

rst.Close
Set rst = Nothing

End Sub

Private Sub Command4_Click()
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM Customers"
DoCmd.SetWarnings True
End Sub

Private Sub Command6_Click()
DoCmd.RunSavedImportExport "Import-Customers"
End Sub

Open in new window


Many thanks,
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

I guess a small sample is needed..but i don't like the rst2 getting all the records without any criteria...
Avatar of Jack Marley
Jack Marley

ASKER

I've attached my database for reference.
Learn5.accdb
You're doing a loop in rst but rst2 stay alway at the first record
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Spot on. Thanks for solving it for me :)