You will have to determine where you want your variables accessible from. The example provided is very generic and uses global variables. For instance gstrPath and gstrFileName are global variables and the procedure will allow for hyperlinks to use these from anywhere within the application.
Similarly, some key values are passed to the procedure. Both, glngCustomerKey and glngDockReceiptKey are used to insure unique directories and file names. These variables are set at the global level.
On the other side of the spectrum you have the following ...
strDocType = "DockReceipt"
This hardcoded "magic string" is really just a place holder for the code snippet provided. Like the global variables used, you need to decide what works best for your application. Ideally you would use variables that survive, only, for the duration of the procedure. In other words, use variables private to the Class or variables defined within the scope of the procedure.
The following (untested) example illustrates how you might employ the sub procedure in a Standard Module and call it from a click event from a form.
In a Standard Module ... (BTW, name your modules something other than the name of a procedure, ie use something like modFullPath)
Code:
Public gstrPath As String
Public gstrFileName As String
Public Sub SetFullPath(ByRef DocType As String, ByRef CustomerKey As Long, ByRef DockReceiptKey As Long)
gstrPath = ""
gstrFileName = ""
Dim strDocPath As String
strDocPath = "C:\Test\Stuff\" & strDocType & "\"
gstrPath = strDocPath & CustomerKey & "\"
gstrFileName = strDocType & "_" & DockReceiptKey
'Make sure the folders exist and make them if they don't
If Dir(strDocPath, vbDirectory) = "" Then
MkDir (strDocPath)
End If
If Dir(gstrPath, vbDirectory) = "" Then
MkDir (gstrPath)
End If
End Sub
And you can call the procedure from a form ...
Code:
SetFullPath "DockReceipt", 500, 952
MsgBox "gstrPath = " & gstrPath
MsgBox "gstrFileName = " & gstrFileName