Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    9

    Unanswered: Data Type Mismatch Error

    And yet another question from the newbie ... sorry everyone.

    I am using the code below to check for duplicate values in a table. In the table Position_ID is set to data type Double. But no matter what I set my variable to in this code I keep getting a "data type mismatch in criteria" error.

    Can you help?

    Code here:

    Dim PID As String 'have also tried Double
    Dim stLinkCriteria as String

    PID = Me.Position_ID.Value
    stLinkCriteria = "[Position_ID] = " & "'" & PID & "'"

    'Check table for duplicate
    If DCount("Position_ID", "tblPosition", stLinkCriteria) > 0 Then
    Me.Undo
    MsgBox "Position Number " & PID & " has already been entered!", vbInformation _
    , "Duplicate Information"

    Me.Position_ID.SetFocus

    Else
    DoCmd.Close
    End If

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Make these changes and it will probably work:

    Dim PID As Double

    stLinkCriteria = "[Position_ID] = " & PID

    Strings should be surrounded by quotes but numbers shouldn't.

  3. #3
    Join Date
    Jul 2004
    Posts
    9
    Oh my ... have I been looking at this database too long today or what?!?

    OK .. I get the "Stupid Question of the Day" award.

    Thanks for the help ... can't believe I didn't catch that!!! Grrrrr! LOL!

Posting Permissions

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