Results 1 to 3 of 3

Simple Problem - Type Mismatch

Threaded View

  1. #1
    Registered User
    Join Date
    10-22-2007
    Posts
    37

    Probably Basic, But 'Type Mismatch'

    I'm new to vba functions, but I have read the documentation and I am still getting a "Type Mismatch," and I can't figure out why. I am taking the value entered into a combobox, assigning it to a string value (strCityName) and trying to determine if it has a space (a space character) within it.

    When I run this it tells me the list where I call InStr has a "Type Mismatch." InStr is supposed to return a 0 as a "Variant Long" value if there is no match and the starting position of the match if one is found. I've declared hasSpace as a Variant (and also As Long - but with the same error showing).

    InStr is supposed to take a String value, and I've defined strCityName as a string. Why am I getting a type mismatch?!


    Dim hasSpace As Variant
    Dim strCityName As String
    
    
    strCityName = boxCity.Value 'define string
    
    hasSpace = InStr(strCityName, " ", 1)
    
    If hasSpace > 0 Then
    
    MsgBox "space detected"
    
    End If
    Last edited by rokuk; 11-16-2007 at 10:25 PM. Reason: more accurate

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1