Solved

Why getting type mismatch error

Posted on 2014-07-27
3
296 Views
Last Modified: 2014-07-30
I have the following code in an oncurrent event of a form.  If I use the line of code:

strPropertyFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtManualPropertyN) & "\"

I get a type mismatch error.  But if I use the line of code:

strPropertyFolderName = TempVars!strPicturesDataPath & "\" & 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:

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

Open in new window

0
Comment
Question by:SteveL13
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
Try with this if you have Null values:

strPropertyFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\" & Trim(Nz(Me.txtManualPropertyN)) & "\"

/gustav
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
If fields are numeric, then try CStr(Me.txtClientID), CStr(Me.txtManualPropertyN)
0
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
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

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now