D
dhoover via AccessMonster.com
I have a form (formA) in which I select a customer from a dropdown box and it
populates the form with the customers info (customer1). I then click a
button which opens formB and populates those fields with the customer1's
information. The code below then clicks a button on formB which runs a
report based on the customer selected in formB, saves the report as an rtf
and then saves the file in the specified client folder. What I need to be
able to do is to click one button that runs this report for each client in my
table and saves each in the specified folder. I'm thinking I need to loop
thorough each customer, but I'm not great at VBA so I need some help.
On Error GoTo Err_cmdCustInfo_Click
Dim strCISFolderPath As String
Dim strFolder5 As String
Dim strfolderpath5 As String
strFolder5 = Dir(strfolderpath5, vbDirectory)
If CISFolderPath <> "" Then
strfolderpath5 = CISFolderPath
strFolder5 = Dir(strfolderpath5, vbDirectory)
End If
'Open the Customer Information form and go to customer selected in Reporting
form
Dim intCustomer As Integer
intCustomer = cmbCustomer
DoCmd.OpenForm "Customer Info"
DoCmd.FindRecord intCustomer, acEntire, , acSearchAll, , acCurrent
DoCmd.OpenReport "Customer Instructions", acViewPreview, , "[ID]=" & [ID]
DoCmd.OutputTo acOutputReport, "Customer Instructions", acFormatRTF,
strfolderpath5 & "\CIS.rtf", False
DoCmd.Close acOutputReport, "customer Instructions", False
DoCmd.Close acForm, "customer info"
Exit_cmdCustInfo_Click:
Exit Sub
Err_cmdCustInfo_Click:
MsgBox Err.Description
Resume Exit_cmdCustInfo_Click
populates the form with the customers info (customer1). I then click a
button which opens formB and populates those fields with the customer1's
information. The code below then clicks a button on formB which runs a
report based on the customer selected in formB, saves the report as an rtf
and then saves the file in the specified client folder. What I need to be
able to do is to click one button that runs this report for each client in my
table and saves each in the specified folder. I'm thinking I need to loop
thorough each customer, but I'm not great at VBA so I need some help.
On Error GoTo Err_cmdCustInfo_Click
Dim strCISFolderPath As String
Dim strFolder5 As String
Dim strfolderpath5 As String
strFolder5 = Dir(strfolderpath5, vbDirectory)
If CISFolderPath <> "" Then
strfolderpath5 = CISFolderPath
strFolder5 = Dir(strfolderpath5, vbDirectory)
End If
'Open the Customer Information form and go to customer selected in Reporting
form
Dim intCustomer As Integer
intCustomer = cmbCustomer
DoCmd.OpenForm "Customer Info"
DoCmd.FindRecord intCustomer, acEntire, , acSearchAll, , acCurrent
DoCmd.OpenReport "Customer Instructions", acViewPreview, , "[ID]=" & [ID]
DoCmd.OutputTo acOutputReport, "Customer Instructions", acFormatRTF,
strfolderpath5 & "\CIS.rtf", False
DoCmd.Close acOutputReport, "customer Instructions", False
DoCmd.Close acForm, "customer info"
Exit_cmdCustInfo_Click:
Exit Sub
Err_cmdCustInfo_Click:
MsgBox Err.Description
Resume Exit_cmdCustInfo_Click