SteveL13
asked on
Why getting type mismatch error
I have the following code in an oncurrent event of a form. If I use the line of code:
strPropertyFolderName = TempVars!strPicturesDataPa th & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtManualPropertyN ) & "\"
I get a type mismatch error. But if I use the line of code:
strPropertyFolderName = TempVars!strPicturesDataPa th & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtID) & "\"
I do not get the error. I don't get it. Both Me.txtID AND me.txtManualPropertyN are number fields.
Here is the entire oncurrent code:
strPropertyFolderName = TempVars!strPicturesDataPa
I get a type mismatch error. But if I use the line of code:
strPropertyFolderName = TempVars!strPicturesDataPa
I do not get the error. I don't get it. Both Me.txtID AND me.txtManualPropertyN are number fields.
Here is the entire oncurrent code:
Private Sub Form_Current()
Dim strPropertyFolderName As String
'strPropertyFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtID) & "\"
strPropertyFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtManualPropertyN) & "\"
If Len(Dir(strPropertyFolderName)) = 0 Then
Me.chkphotos = False
Else
Me.chkphotos = True
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If fields are numeric, then try CStr(Me.txtClientID), CStr(Me.txtManualPropertyN )
Try saving the path to a String variable and displaying it in the Immediate Window, so you can see what is wrong with it. Or just use this code to browse for the folder:
Public Function SelectFolder() As String
'Requires Office XP (2002) or higher
'Requires a reference to the Microsoft Office Object Library
'Created by Helen Feddema 3-Aug-2009
'Last modified 3-Aug-2009
On Error GoTo ErrorHandler
Dim strFolderPath As String
Dim fd As Office.FileDialog
'Create a FileDialog object as a Folder Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Browse for folder where ________________"
.ButtonName = "Select"
.InitialView = msoFileDialogViewDetails
'.InitialFileName = strPath
If .Show = -1 Then
strFolderPath = CStr(fd.SelectedItems.Item(1)) & "\"
Else
Debug.Print "User pressed Cancel"
strFolderPath = ""
End If
End With
SelectFolder = strFolderPath
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in SelectFolder procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Function