Type Mismatch

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bobby Charlton
    New Member
    • Dec 2011
    • 4

    Type Mismatch

    Private Sub search_list(ByR ef house_details() As house_record)

    Code:
    Dim price_target As Currency
    Dim type_target As String
    Dim postcode_target As String
    Dim counter As Integer
    Dim temp_postcode As String
    
    postcode_target = cboOne.Text
    price_target = cboTwo.Text   'Type Mismatch "13"
    type_target = cboThree.Text
    
    For counter = 1 To 7
    
    temp_postcode = house_details(counter).postcode
    temp_postcode = Left(temp_postcode, 3)
      If postcode_target = temp_postcode Or postcode_target = "All" Then
         If price_target = house_details(counter).price Or price_target = "Any" Then
            If type_target = house_details(counter).house_type Or type_target = "Any" Then
            
              OutputForm.txtAddress.Text = house_details(counter).address
              OutputForm.txtPostcode.Text = house_details(counter).postcode
              OutputForm.txtPrice.Text = house_details(counter).price
              OutputForm.txtType.Text = house_details(counter).house_type
              OutputForm.txtStatus.Text = house_details(counter).status
         
          Else
              MsgBox ("No matches for your search criteria")
          End If
        End If
      End If
    Next
    
    End Sub
    I don't know what to do. :(
    Last edited by Stewart Ross; Dec 8 '11, 01:37 PM. Reason: Added code tags to code segment
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Your price_target variable is defined to be of type currency. What is the value in the combo when the error occurs?

    You could try using the CCur function to coerce the value returned from cboTwo to currency as follows:

    price_target = CCur(cboTwo.tex t)

    but we really need to know more about the value of the combo when the error occurs.

    -Stewart

    Comment

    • Bobby Charlton
      New Member
      • Dec 2011
      • 4

      #3
      I think it's mainly because I'm using numbers. The search values stored in cboTwo has string contents such as a pound sign. (£) Is there a way to get around this? (Total novice here).

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        The type conversion function CCur works fine when faced with the local currency sign prefixing a numeric string (the prefix being the UK pound sign in this case).

        Have you tried the explicit typecasting using CCur I suggested above? It does not error when faced with a text string representing an amount in UK pounds.

        -Stewart

        Comment

        Working...