Solved

Why getting type mismatch error

Posted on 2014-07-27
3
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40222721
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
ID: 40224112
If fields are numeric, then try CStr(Me.txtClientID), CStr(Me.txtManualPropertyN)
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 40225160
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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