Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I need to put the date in the

Status
Not open for further replies.

integritycare

Technical User
Mar 12, 2011
151
AU
Hi,
I need to put the date in the filename of an access report. I have tried this code as below. The report opens as a PDF OK, but no date.
Got some error here. Any bright suggestions would be appreciated.
Code:
Private Sub Master_Report_Click()
Dim FilePath As String
Dim FileName As String
FilePath = "C:\Users\K\Desktop\Master Report PDF"
FileName = FilePath & Format(Date, "MM-DD-YYYY") & " Master Report"
DoCmd.OutputTo acOutputReport, "Master Report", acFormatPDF, strFullPath, True
End Sub
Thank you..
 
Does your code compile?
You are using strFullPath in your DoCmd line but it has no source/value from what we can tell.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Hi Duane,
Thanks for your reply.
Yes the DB does compile. It shows no errors.
 
Do you have Option Explicit at the top of all of your modules?

Do you understand you are setting the value of [highlight #FCE94F]FileName[/highlight] but using [highlight #FCE94F]strFullPath[/highlight]?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Hi Duane,
Just had to check the option explicit, Had missed out on a couple of forms.
When you compile the Db now shows "Variable not defined on the strFullPath"
But just not sure where to go from here.
What is the better way to write this vba?

Thanks
KP
 
[tt]DoCmd.OutputTo acOutputReport, "Master Report", acFormatPDF, [blue]FilePath[/blue] , True
[/tt]
 
Hi Guys,
Thanks for the info.
I have now got it working quite well. have changed thee vba to read as below,

Code:
Private Sub Master_Report_Click()
Dim FilePath As String
FilePath = "C:\PDFTemp\Master Report,     -" & Format(Date, "dd-mm-yyyy") & ".pdf"
DoCmd.OutputTo acOutputReport, "Master Report", acFormatPDF, FilePath, True
End Sub
The question is if it works is the vba right?.... The space between "Master report" & Date function is for the user to insert his Branch ID
Many thanks,

KP
 
Are you expecting your code to stop and wait for the user to enter something?
Isn't the user's branch ID stored in a table that you can retrieve?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Hi Duane,
This code is on a command button. When run, the report opens in PDF and when is is saved as a PDF with the ability for the user to input his Branch ID, however,
Yes, there is a table with the Branch ID plus BranchName etc, but I am just not sure how to add this to the vba.
This table is linked to a table which holds the users logonID and username.

Thanks,
KP
 
Do you have any code in your application that can identify the current user? Maybe a function that returns the network login of the current user? Are the user logins stored in your "table with the Branch ID plus BranchName etc"? Is there any other automated ways to get the value you want from the table? Can you add a dropdown on your form to select the Branch ID?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Hi Duane,
To answer your questions,
Within the relationships the Branch table is linked to the User table (one to many) so when a new user is assigned to any branch he has a specific ID linked to that Branch.
So it would be quite easy to put a dropdown on the form to select the BranchID.
So with a query its possible to see the relationship between the user and the assigned Branch.
Hope this makes sense!
 
Ok, add the dropdown and set its bound column to the value you want to use in the file name.

Code:
Private Sub Master_Report_Click()
    Dim FilePath As String
    FilePath = "C:\PDFTemp\Master Report " & [highlight #FCE94F]Me.[YourComboBoxNameHere][/highlight] & "-" & Format(Date, "dd-mm-yyyy") & ".pdf"
    DoCmd.OutputTo acOutputReport, "Master Report", acFormatPDF, FilePath, True
End Sub

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top