shannonsims
New member
- Local time
- Today, 14:56
- Joined
- Apr 4, 2013
- Messages
- 8
I recently drafted the below code that allows me to track administrative documents for personnel in Access 2010 and save a PDF of the document on a shared drive in order to keep the database from bloating beyond the 2GB limit.
I'm now trying to save the attachment with a name that is based on 3 fields from the form that allow for effective sorting and filing of the PDF attachment but have no clue where to start. The field names and types are:
Employee: combo box
DocDescription: combo box
DocDate: date
An example of how I would like VBA to format the new name for the PDF is "DocDate_Employee_DocDescription.pdf"
Any guidance is appreciated as I'm a novice VBA guy.
I'm now trying to save the attachment with a name that is based on 3 fields from the form that allow for effective sorting and filing of the PDF attachment but have no clue where to start. The field names and types are:
Employee: combo box
DocDescription: combo box
DocDate: date
An example of how I would like VBA to format the new name for the PDF is "DocDate_Employee_DocDescription.pdf"
Any guidance is appreciated as I'm a novice VBA guy.
Code:
Private Sub AdminDocPath_DblClick(Cancel As Integer)
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'the number of the button chosen
Dim FileChosen As Integer
FileChosen = fd.Show
'1) To set the caption of the dialog box, set the Title property
fd.Title = "Select Admin Document to Upload"
'2) Set the oddly named InitialFileName property to determine the initial folder selected
fd.InitialFileName = "C:\Users\swsims\Desktop\E-Pers Test\Admin Docs"
'3) Set the InitialView property to control how your files appear on screen (as a list, icons, etc.)
fd.InitialView = msoFileDialogViewSmallIcons
'4) To set the filters (you can have as many as you like) first clear any existing ones, then add them one by one
fd.Filters.Clear
fd.Filters.Add "PDF macros", "*.pdf"
fd.Filters.Add "Excel macros", "*.xlsm"
' if there's more than one filter, you can control which one is selected by default
fd.FilterIndex = 1
' if there's more than one filter, you can control which one is selected by default
fd.FilterIndex = 1
'5) Set the ButtonName property to control the text on the OK button (the ampersand means the following letter is underlined and choosable with the ALT key)
fd.ButtonName = "Select file"
If FileChosen <> -1 Then
'didn't choose anything (clicked on CANCEL)
MsgBox "Upload Cancelled"
Else
'display name and path of file chosen
MsgBox fd.SelectedItems(1)
End If
'store the selected file to a variable
strSelectedFile = fd.SelectedItems(1)
'parse out the filename from the path
strFilename = Right(strSelectedFile, Len(strSelectedFile) - InStrRev(strSelectedFile, "\"))
'build the destination
strDestination = "C:\Users\swsims\Desktop\E-Pers Test\Admin Docs\" & strFilename
'copy the file to the new folder
FileCopy strSelectedFile, strDestination
'store file as part of the record
Me.AdminDocPath = strFilename
'save hyperlink as part of record
Me.AdminDocLink = strDestination
End Sub