Recently, I stumbled onto some code that is supposed to place a browse button onto a form, and a textbox with the name of the file the user selects. Before I get to the code, I'll explain exactly what I want.
Essentially, what I want is to have an "Extras" folder. This folder will hold more information for specific records in the forms. I want the user to be able to, on the click of a button, look through that folder and find the correct file. Once it's found, I want the address of that file to be stored in a textbox, and then I want the user to be able to click the textbox (hyperlink probably?) to bring up the file whenever they want.
Here is the code. I think it's basically what I want, but I can't get it to work.
The button is of course named bBrowse and I have a textbox called tbHidden and a textbox called tbFile as well. I'm getting an error on the strDialogTitle:="Find File (Select The File And Click The Open Button)") line. Any help would be appreciated.
Essentially, what I want is to have an "Extras" folder. This folder will hold more information for specific records in the forms. I want the user to be able to, on the click of a button, look through that folder and find the correct file. Once it's found, I want the address of that file to be stored in a textbox, and then I want the user to be able to click the textbox (hyperlink probably?) to bring up the file whenever they want.
Here is the code. I think it's basically what I want, but I can't get it to work.
Code:
Private Sub bBrowse_Click()
On Error GoTo Err_bBrowse_Click
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
Me.tbHidden.SetFocus
' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*"
strFilter = "All Files (*.*)" & vbNullChar & "*.*"
lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly
varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngFlags, _
strInitialDir:="C:\Windows\", _
strDialogTitle:="Find File (Select The File And Click The Open Button)")
'remove the strInitialDir:="C:\Windows\", _ line if you do not want the Browser to open at a specific location
If IsNull(varFileName) Or varFileName = "" Then
Debug.Print "User pressed 'Cancel'."
Beep
MsgBox "File selection was canceled.", vbInformation
Exit Sub
Else
'Debug.Print varFileName
tbFile = varFileName
End If
Call ParseFileName
Exit_bBrowse_Click:
Exit Sub
Err_bBrowse_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_bBrowse_Click
End Sub
The button is of course named bBrowse and I have a textbox called tbHidden and a textbox called tbFile as well. I'm getting an error on the strDialogTitle:="Find File (Select The File And Click The Open Button)") line. Any help would be appreciated.