LanaR
Member
- Local time
- Today, 15:27
- Joined
- May 20, 2021
- Messages
- 113
I have the following code under a button, which opens the file explorer window, and then moves the selected document to the target file and notes its location in the DB. In 64 bit the file explorer windows does not open and the MsgBox "File selection was canceled.", vbInformation is shown
Code:
Private Sub Command115_Click()
On Error GoTo Err_bBrowse_Click
'check if tasting note already attached
'if no note then add PDF Location
If Me.tbFile = "" Or IsNull(Me.tbFile) Then
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' 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
' Additional procedure to move file to correct destination
Dim sSource As String
Dim sTarget As String
Dim sFName As String
'Set File Source
sSource = Me.tbFile
'Determine the the Name of the file to be moved
sFName = Mid(sSource, InStrRev(sSource, "\"), Len(sSource) - (InStrRev(sSource, "\") - 1))
'Set File destination
sTarget = "C:\MS Office Data\PDF\WineTastingNotes" & sFName
'Copy file to destination
VBA.FileCopy sSource, sTarget
'Set cirrect location for file
Me.tbFile = sTarget
'Delete Original
VBA.Kill sSource
'Additional Procedure to append Remark to tasting Notes
Dim StrSQL As String
StrSQL = "INSERT INTO TBL_TastNote ( WineID, AuthID, [Note] ) " & _
"SELECT TBL_Wine.WineID, 4 AS Expr1, 'See Attatched PDF' AS Expr2 " & _
"FROM TBL_Wine " & _
"WHERE (((TBL_Wine.WineID)=[forms]![FRM_Wine]![WineID])); "
DoCmd.RunSQL StrSQL
End If
'Call ParseFileName <= this was in original code but caused an error
'Change caption of Button and make PDF Icon visible
Me.Command115.Caption = "View PDF Tasting Note"
Me.OLEUnbound119.Visible = True
'if Notes already attached
'View note
Else
OpenFile (tbFile)
End If
Exit_bBrowse_Click:
Exit Sub
Err_bBrowse_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_bBrowse_Click
End Sub