Save file in specific location

Bumi66

New member
Local time
Today, 00:31
Joined
Jan 15, 2019
Messages
19
I'm trying to save a file in a specific location on my hard drive.
The location should be m:\Order acknowledgment\Customer name\Order number.pdf

The customer name is in a field in my form "match" this varies
also the Order number is in a field in the form under "Order number"

This is my Code but it doesn't work


Private Sub Command240_Click()
Dim Match As String

DoCmd.OutputTo acOutputReport, "Order Confirmation", acFormatPDF, "m:\Order acknowledgement\" " str.Match "\" & Me.Order number & ".pdf", True

End Sub

What did I do wrong I'm new to VBA please help
 
Create a couple of strings and break this down into sensible steps so you can see what is happening.

Code:
Dim sTopPath as String
Dim sCust       as String
Dim sOrdNo   as String
Dim sFullPath as string

sTopPath ="M:\Order acknowledgement\"
sCust = Me.CustomerName   ' Where Customername is the name of the control on your form
sOrdNo = Me.OrderNumber 

sFullPath = sTopPath & sCust & "\" & sOrdNo & ".pdf"

Debug.print sFullPath            ' You can see this in the immediate window in the VBA editor - press ctrl + G to view it

DoCmd.OutputTo acOutputReport, "Order Confirmation", acFormatPDF, sFullPath , True

Always put concatenated strings into a separate string to help with debugging.
 
Hi. The first thing I would recommend is to add Option Explicit at the top of your Module.
 
Create a couple of strings and break this down into sensible steps so you can see what is happening.

Code:
Dim sTopPath as String
Dim sCust       as String
Dim sOrdNo   as String
Dim sFullPath as string

sTopPath ="M:\Order acknowledgement\"
sCust = Me.CustomerName   ' Where Customername is the name of the control on your form
sOrdNo = Me.OrderNumber

sFullPath = sTopPath & sCust & "\" & sOrdNo & ".pdf"

Debug.print sFullPath            ' You can see this in the immediate window in the VBA editor - press ctrl + G to view it

DoCmd.OutputTo acOutputReport, "Order Confirmation", acFormatPDF, sFullPath , True

Always put concatenated strings into a separate string to help with debugging.
 
Thank you so much, you made my day, It works
Create a couple of strings and break this down into sensible steps so you can see what is happening.

Code:
Dim sTopPath as String
Dim sCust       as String
Dim sOrdNo   as String
Dim sFullPath as string

sTopPath ="M:\Order acknowledgement\"
sCust = Me.CustomerName   ' Where Customername is the name of the control on your form
sOrdNo = Me.OrderNumber

sFullPath = sTopPath & sCust & "\" & sOrdNo & ".pdf"

Debug.print sFullPath            ' You can see this in the immediate window in the VBA editor - press ctrl + G to view it

DoCmd.OutputTo acOutputReport, "Order Confirmation", acFormatPDF, sFullPath , True

Always put concatenated strings into a separate string to help with debugging.
 
Thank you so much, you made my day, It works

You should take note of the instruction to add Option Explicit to all your code modules.

And now would be a good time to remove all the spaces from your field names, and give you controls sensible names.
Have a read about a naming convention, and reserved words and special characters.
 
Never use drive letter paths.
Always use UNC server paths: \\server\folder\folder\file.txt
 

Users who are viewing this thread

Back
Top Bottom