Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Data Type Mismatch Error

Discussion in 'Information Technology' started by j, Jul 28, 2006.

  1. j

    j
    Expand Collapse
    Guest

    I am working on a project and am getting a simple error that has me stumped.
    printout and 'may 2008$' are two recordsets/tables in this database. Each has
    matching information that I want to compare.The matching information is
    ExportID and Export. Both fields are strings (though they are all numeric
    characters). ID is a unique identifier beggining with 1 that is in the
    printout database but not 'may $2008'. However, I get a "data type mismatch
    in criteria expression" referring to the final line in the pasted text. Does
    anyone know how to fix this problem, thank you!!

    Dim dbMyDB As Database
    Set dbMyDB = OpenDatabase("myproject.mdb")

    Dim first As Recordset
    Set first = dbMyDB.OpenRecordset("printout", dbOpenDynaset)

    Dim second As Recordset
    Set second = dbMyDB.OpenRecordset("'May 2008'$", dbOpenDynaset)

    Dim custID As String
    Dim p As Double

    p = 1
    'later I will loop p to do this for many IDs

    first.FindFirst "ID = " & CStr(p)
    custID = first!ExportID
    second.FindFirst "[Export] = " & custID
     
  2. Loading...


  3. Ofer Cohen

    Ofer Cohen
    Expand Collapse
    Guest

    When you search on a string field, you need to add a single quote before and
    after the value, either wise it will treat it as a number, and this is why
    you are propmpt with type mismatch

    try
    first.FindFirst "ID = '" & CStr(p) & "'"


    --
    Good Luck
    BS"D


    "j" wrote:

    > I am working on a project and am getting a simple error that has me stumped.
    > printout and 'may 2008$' are two recordsets/tables in this database. Each has
    > matching information that I want to compare.The matching information is
    > ExportID and Export. Both fields are strings (though they are all numeric
    > characters). ID is a unique identifier beggining with 1 that is in the
    > printout database but not 'may $2008'. However, I get a "data type mismatch
    > in criteria expression" referring to the final line in the pasted text. Does
    > anyone know how to fix this problem, thank you!!
    >
    > Dim dbMyDB As Database
    > Set dbMyDB = OpenDatabase("myproject.mdb")
    >
    > Dim first As Recordset
    > Set first = dbMyDB.OpenRecordset("printout", dbOpenDynaset)
    >
    > Dim second As Recordset
    > Set second = dbMyDB.OpenRecordset("'May 2008'$", dbOpenDynaset)
    >
    > Dim custID As String
    > Dim p As Double
    >
    > p = 1
    > 'later I will loop p to do this for many IDs
    >
    > first.FindFirst "ID = " & CStr(p)
    > custID = first!ExportID
    > second.FindFirst "[Export] = " & custID
    >
     

Share This Page