Might be a daft question but the functionality of the attachments on an Access DB form. Double click on the field and it opens a form with a listbox (guess) and 7 button on it...
Is this form and code documented anywhere?
It will be quite a pain to have to recode it so thought I'd ask.
I not gone down the route of filestream etc but storing pointers in the DB instead, right now SSMA will just give the filename, no path information. 80%+ are in the same location so didn't want to hard code it. 100% are on shared drives.
I use the split function to take the multi entry attachments field to populate variables etc, and checked with msgbox that I have done it right...
The ideas came from this forum so kudos to those involved.
I stripped out the error handling (used the on error goto for now which I am sure might not be the best option)
So I sharing... this is how I had done part of it... if say a 'add' button were selected.
Is this form and code documented anywhere?
It will be quite a pain to have to recode it so thought I'd ask.
I not gone down the route of filestream etc but storing pointers in the DB instead, right now SSMA will just give the filename, no path information. 80%+ are in the same location so didn't want to hard code it. 100% are on shared drives.
I use the split function to take the multi entry attachments field to populate variables etc, and checked with msgbox that I have done it right...
The ideas came from this forum so kudos to those involved.
I stripped out the error handling (used the on error goto for now which I am sure might not be the best option)
So I sharing... this is how I had done part of it... if say a 'add' button were selected.
Code:
'Taken from threads here unc-filepath-from-file-selector-dialog.308912
' This works every time.
Option Compare Database
Private Sub cmdFileDialog2_Click()
'It's a shared application and some don't always map the same drive letter this means will have to go to UNC paths
'High level overview:
'First opens a file selector to allow the user to select a file
'Second, the filepath of the selected file is stored into variable "RawHyperlink"
'Next it extracts the drive letter and stores it to variable "DriveLetter"
'The remaining subfolders and filename are stored to variable "FolderFile"
'It converts the value in DriveLetter to a UNCPath using the GETNETWORKPATH module
'Finally it merges the UNCPath and FolderFile back into a usable hyperlink, and populates it into a clickable textbox "TxtFileHyperlink"
'need to substitute this in for the normal browse and add the filters
'this will then populate the original attachment link
Dim f As Object
Dim RawHyperlink As String
'for the delimiter
'currently use different ones but will get them to standardise on ;
Dim strchar As String
'I added some filters so only cerain filetypes could be chosen
Set f = Application.FileDialog(3)
'maybe add the filters:
f.Filters.Clear
f.Filters.Add "Text/CSV files", "*.txt, *.csv"
f.Filters.Add "Excel/Word files", "*.doc;*.docx;*.xls;*.xlsx;*.xlsm"
f.Filters.Add "PDF files", "*.pdf"
'I think this might need attention ?
f.AllowMultiSelect = True
'The non UNC used f.AllowMultiSelect = True as they were allowed to select several files at once
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = nameoffile(f.SelectedItems(i), sPath)
RawHyperlink = sPath & sFile
DriveLetter = Left(RawHyperlink, 2)
FolderFile = Mid(RawHyperlink, 3)
UNCPath = GETNETWORKPATH(DriveLetter)
txtFileHyperlink = UNCPath & FolderFile
'this msgbox is just here as debug
'Note select a file local then there is no UNCPath
'The msgbox for the different variables to see how they get built up.
MsgBox "RawHyperlink: " & RawHyperlink & vbCrLf & _
"DriveLetter: " & DriveLetter & vbCrLf & _
"UNCPath: " & UNCPath & vbCrLf & _
"File: " & sFile
MsgBox "Filename:" & txtFileHyperlink
'need to add in logic to add ; character if there is more than one of these as there are in almost all cases
'do not forget to make the variable equal what the data is the textbox
txtFileHyperlink = filename
If txtFileHyperlink = "" Then
strchar = ""
Else
strchar = ";"
End If
txtFileHyperlink = txtFileHyperlink + strchar & "" & UNCPath & "" & FolderFile
'this msgbox is just here as debug
MsgBox "Filename:" & txtFileHyperlink
filename = txtFileHyperlink
Next
End If
End Sub
Public Function nameoffile(ByVal strNetPath As String, sNetPath) As String
sNetPath = Left(strNetPath, InStrRev(strNetPath, "\"))
nameoffile = Mid(strNetPath, InStrRev(strNetPath, "\") + 1)
End Function
Private Sub cmdFileSelector_Click()
MsgBox GETNETWORKPATH(txtNetworkDriveLetter)
End Sub
Public Function GETNETWORKPATH(ByVal DriveName As String) As String
Dim objNtWork As Object
Dim objDrives As Object
Dim lngLoop As Long
Set objNtWork = CreateObject("WScript.Network")
Set objDrives = objNtWork.enumnetworkdrives
For lngLoop = 0 To objDrives.Count - 1 Step 2
If UCase(objDrives.Item(lngLoop)) = UCase(DriveName) Then
GETNETWORKPATH = objDrives.Item(lngLoop + 1)
Exit For
End If
Next
End Function
Last edited: