Results 1 to 5 of 5
  1. #1
    DCV0204 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    85

    Run-time error '13' Type mismatch

    Hello, I have a form that contains an unbound textbox named "Srch_MedID" my code below worked until I tried to search for an ID that contained an alpha. When I try to search lets say 'H445238' I receive the run-time error; if I search '1234567' it finds the record and opens the form. Can you tell me what I am missing?

    Private Sub btnsrch_Click()
    Dim MedID As String



    ' Get Value from Medicaid_ID textbox on the Form:
    Me.SrchMed_ID.SetFocus
    MedID = Me.SrchMed_ID.Text


    Dim Msg, Style, Title, Response, MyString

    If IsNull(DLookup("[Medicaid_ID]", "Returned_Mail", "Medicaid_ID = '" & SrchMed_ID & "'")) Then
    DoCmd.OpenForm "RA_Tracking", , , , acFormAdd
    Me.SrchMed_ID = ""
    Else
    If (DLookup("[Medicaid_ID]", "Returned_Mail", "Medicaid_ID = '" & SrchMed_ID & "'" & _
    "And IsNull([SuppressDate])")) Then
    DoCmd.OpenForm "RA_Tracking", , , "Returned_Mail.Medicaid_ID = '" & SrchMed_ID & "'"
    Me.SrchMed_ID = ""

    Else
    MsgBox ("Do not log RA's for this Medicaid ID:" & (Chr(13)) & (Chr(13)) & " " & [SrchMed_ID] & (Chr(13)) & (Chr(13)) & "Recycle this providers RA's")
    Me.SrchMed_ID = ""


    End If
    End If


    End Sub



    Thanks.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    A few things:

    In Access,
    strings are delimited with ".... eg MyString = "abcde" or "abc123"
    dates are delimited with # ... eg #07/05/2013#
    numbers/numerics have no delimiter ...eg MyNumber = 12345

    Numbers can not have alpha characters.

    This structure/syntax
    Dim Msg, Style, Title, Response, MyString
    Declares all of these to be of type Variant
    Access requires you to explicitly define types, else you'll get Vaiant

    Dim MyString as String, MyInt as Integer, MyLong as Long
    or
    Dim MyString as String
    Dim MyInt as Integer
    Dim MyLong as Long

  3. #3
    DCV0204 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    85
    Ok, I have changed my code to:

    Private Sub btnsrch_Click()
    Dim MedID As String
    Dim SrchMed_ID As String
    Dim Medicaid_ID As String


    ' Get Value from Medicaid_ID textbox on the Form:
    Me.SrchMed_ID.SetFocus
    MedID = Me.SrchMed_ID.Text


    'Dim Msg, Style, Title, Response, MyString

    If IsNull(DLookup("[Medicaid_ID]", "Returned_Mail", "Medicaid_ID = '" & SrchMed_ID & "'")) Then
    DoCmd.OpenForm "RA_Tracking", , , , acFormAdd
    Me.SrchMed_ID = ""
    Else
    If (DLookup("[Medicaid_ID]", "Returned_Mail", "Medicaid_ID = '" & SrchMed_ID & "'" & _
    "And IsNull([SuppressDate])")) Then
    DoCmd.OpenForm "RA_Tracking", , , "Returned_Mail.Medicaid_ID = '" & SrchMed_ID & "'"
    Me.SrchMed_ID = ""

    Else
    MsgBox ("Do not log RA's for this Medicaid ID:" & (Chr(13)) & (Chr(13)) & " " & [SrchMed_ID] & (Chr(13)) & (Chr(13)) & "Recycle this providers RA's")
    Me.SrchMed_ID = ""


    End If
    End If


    End Sub

    I no longer get the run-time error; but it will not find the record in my table for the Medicaid ID now.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    ' Get Value from Medicaid_ID textbox on the Form:
    Me.SrchMed_ID.SetFocus
    MedID = Me.SrchMed_ID.Text
    What is the name of the textbox on the Form? Is it Medicaid_ID

    What is Me.SrchMed_ID ?

    Can you post a copy of your database (no confidential info)?

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As orange is suggesting, this makes no sense! Your code that he included

    Code:
    Me.SrchMed_ID.SetFocus
    MedID = Me.SrchMed_ID.Text


    tells us that SrchMed_ID is a Control on your Form. But with this

    Dim SrchMed_ID As String

    you're telling us that SrchMed_ID is a Variable! It can't be both!

    Then you do something similar with Medicaid_ID; you use it as a Field, in the DLookup:

    If IsNull(DLookup("[Medicaid_ID]", "Returned_Mail", "Medicaid_ID = '" & SrchMed_ID & "'")) Then

    but you declare it, too, as a Variable, with

    Dim Medicaid_ID As String

    and it simply can't be both. As orange said, you really need to strip it (of sensitive data) and zip it, and post it here for us to look at.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run-time error 13 type Mismatch
    By Jaron in forum Programming
    Replies: 2
    Last Post: 09-13-2013, 02:33 PM
  2. Run-time error 13: type mismatch
    By ehe in forum Programming
    Replies: 3
    Last Post: 01-13-2013, 12:58 AM
  3. run-time error '13' type mismatch
    By teebumble in forum Forms
    Replies: 8
    Last Post: 12-03-2012, 01:18 PM
  4. run-time error 13 , type mismatch
    By Compufreak in forum Programming
    Replies: 8
    Last Post: 08-13-2012, 12:17 AM
  5. Run-time error '13': Type mismatch
    By uronmapu in forum Access
    Replies: 2
    Last Post: 07-10-2012, 07:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums