Results 1 to 12 of 12

Thread: Type Mismatch

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    86

    Type Mismatch

    I am trying to match the first two character's in a forms textbox with a 2 digit text field from a table and I'm getting type mismatch.
    What am I doing wrong?


    Private Sub loadList()

    Dim db As Database

    Dim TemptxtPatNO As String * 2


    Set db = CurrentDb


    TemptxtPatNO = Mid(txtPatNo, 1, 2)


    Combo69.RowSource = "SELECT qry_Clinic.[clinicID] & " - " & qry_Clinic.[ClinicName] AS IDName" & _
    "FROM qry_Clinic & qry_Clinic" & _
    "Where TemptxtPatNO = qry_Clinic.[ClinicAgencyID];"


    End Sub

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    You're gonna need some quotes in there...
    And you can't put the variable into the SQL string like that. Try this:

    VB Code:
    1. Private Sub loadList()
    2.  
    3.   Dim db As Database
    4.   Dim TemptxtPatNO As String * 2
    5.  
    6.   Set db = CurrentDb
    7.  
    8.   TemptxtPatNO = Mid(txtPatNo, 1, 2)
    9.  
    10.   Combo69.RowSource = "SELECT qry_Clinic.[clinicID] & " - " & qry_Clinic.[ClinicName] AS IDName" & _
    11.   "FROM qry_Clinic & qry_Clinic" & _
    12.   "Where qry_Clinic.[ClinicAgencyID] = '" & TemptxtPatNO & "';"
    13.  
    14. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    86

    Type Mismatch

    Still getting a type mismatch error

  4. #4
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Just noticed - did you know you have qryClinic & qryClinic in your FROM clause?

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Hi

    If you are getting type mis match its because your types are wrong when matching (numbers to text and visa versa).

    So Pilgrim Pete is right with this
    Combo69.RowSource = "SELECT qry_Clinic.[clinicID] & " - " & qry_Clinic.[ClinicName] AS IDName FROM qry_Clinic Where qry_Clinic.[ClinicAgencyID] = '" & TemptxtPatNO & "';"

    Except the single quotes aren't required (remove them)

    Try that

    Regards

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    You also need spaces at the end of the clauses.
    I'll give it another try...

    VB Code:
    1. Private Sub loadList()
    2.  
    3.   Dim db As Database
    4.   Dim TemptxtPatNO As String * 2
    5.  
    6.   Set db = CurrentDb
    7.  
    8.   TemptxtPatNO = Mid(txtPatNo, 1, 2)
    9.  
    10.   Combo69.RowSource = "SELECT qry_Clinic.[clinicID] & " - " & qry_Clinic.[ClinicName] AS IDName " & _
    11.   "FROM qry_Clinic " & _
    12.   "Where qry_Clinic.[ClinicAgencyID] = '" & TemptxtPatNO & "';"
    13.  
    14. End Sub

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    86

    Type Mismatch

    combo69 is a combobox on a form called addvisit. I declare the variable temptxtPatno as a string of length 2, and clinicAgencyId is in a table as a text field of size 2. I am still getting the type mismatch error with or without the single quotes. Please help

  8. #8
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    OK. I'm at a bit of a loss; let's take a step back.

    First - when you go into debug mode which line are you on?
    Next - does TemptxtPatNO definitely have a value when you get to the RowSource line?
    Finally, if none of these makes the solution jump out at you, can you add these lines before the RowSource line:
    VB Code:
    1. dim strSQL as string
    2. strSQL= "SELECT qry_Clinic.[clinicID] & " - " & qry_Clinic.[ClinicName] AS IDName " & _
    3.   "FROM qry_Clinic " & _
    4.   "Where qry_Clinic.[ClinicAgencyID] = '" & TemptxtPatNO & "';"
    5. debug.print strSQL
    and post the resultant string?

  9. #9
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Hi

    You are using in Access, so use the query builder.
    Then once you have the filter (put a test value in as the filter), change the query builder to SQL view. Copy this and paste into your code then change the where clause to use the combo box.
    (see previous examples).

    Since you are basing on a query the type may be changing, or there is a problem with the base query. Might be worth ensuring that works.

    Other than that you'll have to list the tables (and fields, types etc) in the base query and the sql of the base query. Or compress and zip the mdb and post up here on a zip file (less than 100k though). We can d/l and look for you then.

    Regards

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  10. #10
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Got it!!

    You ever have one of those "can't see for looking" days??

    It's your double quotes around the hyphen. Either double 'em up, or make 'em singles, like this:
    VB Code:
    1. "SELECT qry_Clinic.[clinicID] & "" - "" & qry_Clinic.[ClinicName] AS IDName "
    2. 'or
    3. "SELECT qry_Clinic.[clinicID] & ' - ' & qry_Clinic.[ClinicName] AS IDName "

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    86

    Type Mismatch.

    Thanks.

  12. #12
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    No probs. Sory it took so long!

Posting Permissions

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



Click Here to Expand Forum to Full Width