PROBLEM: Strange Bar Characters being returned in file name and path being returned from common dialog ("|"
This seems to work fine up until the final step. The strange thing is that the message box pops up showing the correct file name and path but it errors out when attempting to write to the field because it says there are too many characters. When I check the variable results in the immediate window it shows cdlg.name as "my path and file name" and "|||||||||||||||||||||||||||||||||" bars like this on the end. Anyone have a solution or explanation about this?
Here is my code:
Private Sub cmdInstall_Click()
Dim cdlg As New CommonDialogAPI
Dim lngFormName As Long
Dim lngAppInstance As Long
Dim strInitDir As String
Dim strFileFilter As String
Dim lngResult As Long
lngFormName = Me.hwnd
lngAppInstance = Application.hWndAccessApp
strInitDir = "C:\My Documents\"
strFileFilter = "Access Databases (*.mdb, *.mde)" & Chr(0) & "*.mdb; *.mde" & Chr(0)
lngResult = cdlg.OpenFileDialog(lngFormName, lngAppInstance, strInitDir, strFileFilter)
If cdlg.GetStatus = True Then
MsgBox "You selected file: " & cdlg.GetName
Me.InstallFile = Trim(cdlg.GetName)
Else
MsgBox "No file selected."
End If
End Sub
This seems to work fine up until the final step. The strange thing is that the message box pops up showing the correct file name and path but it errors out when attempting to write to the field because it says there are too many characters. When I check the variable results in the immediate window it shows cdlg.name as "my path and file name" and "|||||||||||||||||||||||||||||||||" bars like this on the end. Anyone have a solution or explanation about this?
Here is my code:
Private Sub cmdInstall_Click()
Dim cdlg As New CommonDialogAPI
Dim lngFormName As Long
Dim lngAppInstance As Long
Dim strInitDir As String
Dim strFileFilter As String
Dim lngResult As Long
lngFormName = Me.hwnd
lngAppInstance = Application.hWndAccessApp
strInitDir = "C:\My Documents\"
strFileFilter = "Access Databases (*.mdb, *.mde)" & Chr(0) & "*.mdb; *.mde" & Chr(0)
lngResult = cdlg.OpenFileDialog(lngFormName, lngAppInstance, strInitDir, strFileFilter)
If cdlg.GetStatus = True Then
MsgBox "You selected file: " & cdlg.GetName
Me.InstallFile = Trim(cdlg.GetName)
Else
MsgBox "No file selected."
End If
End Sub