Dynamic File name based on field in the report

Bancell

New Member
Joined
Mar 22, 2004
Messages
41
I am trying to figure out how to have a file that is being exported via a macro to automatically use the field "Group Of Technician" from the "partsUsuageReport" to a specific location. I have been able to get the file to export and save to the correct location but have not been able to figure out how to get the file name correct. From everything I have read I will need to use VBA for this. Unfortunately I dont understand VBA at all at this point. I am working on learning it but the light hasnt clicked on yet. A lot of the code I am seeing online doesnt look anything like what I have here so I'm not sure what Im doing wrong.

Any suggestions?






'------------------------------------------------------------
' OpenReport_Click
'
'------------------------------------------------------------
Private Sub OpenReport_Click()
On Error GoTo OpenReport_Click_Err

DoCmd.OpenReport "PartsUsuageReport", acViewReport, "", "", acNormal
DoCmd.OutputTo acOutputReport, "PartsUsuageReport", "PDFFormat(*.pdf)", "T:\Brad&Bill\Tech Inventories\Parts Usauge Reports\Parts Usauge Report.pdf", False, "", , acExportQualityPrint


OpenReport_Click_Exit:
Exit Sub

OpenReport_Click_Err:
MsgBox Error$
Resume OpenReport_Click_Exit

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I tend to define a base path lets say called strPath with a value of "T:\Brad&Bill\Tech Inventories\Parts Usauge Reports\"
I would also parameterise the report name
strReport = "PartsUsuageReport"

Then you would use something like
Rich (BB code):
DoCmd.OutputTo acOutputReport, strReport, "PDFFormat(*.pdf)", strPath & strReport & "-" & [Group Of Technician] & ".pdf", False, "", , acExportQualityPrint


HTH
 
Upvote 0
Thank you for the quick reply!


Ok so this is what I have now. I am now getting the following error when I try to run the report. "Microsoft Access can't find the field '|1' referred to in your expression"




'------------------------------------------------------------
' OpenReport_Click
'
'------------------------------------------------------------
Private Sub OpenReport_Click()
On Error GoTo OpenReport_Click_Err

DoCmd.OpenReport "PartsUsuageReport", acViewReport, "", "", acNormal
strPath = "T:\Brad&Bill\Tech Inventories\Parts Usauge Reports"
strReport = "PartsUsuageReport"
DoCmd.OutputTo acOutputReport, strReport, "PDFFormat(*.pdf)", strPath & strReport & "-" & [Group Of Technician] & ".pdf", False, "", , acExportQualityPrint



OpenReport_Click_Exit:
Exit Sub

OpenReport_Click_Err:
MsgBox Error$
Resume OpenReport_Click_Exit

End Sub
 
Upvote 0
I got it to work. I just had to put in [reports]![PartsUsuageReport]![group of technician] and it worked!!

Thank you for the assistance!!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

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