Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2011
    Posts
    47

    Unanswered: Runtime error "13"

    Hi,

    I have adapted this code to prevent double entry, however when i run the code i get a runtime error "13" and "type mismatchn" and it highlights the stlinkcriteria expression

    stlinkcriteria expression
    :

    stLinkCriteria = "[FileNumber]=" & "'" & SID & "'"

    The code is:

    Private Sub FileNumber_BeforeUpdate(Cancel As Integer)
    Dim SID As String
    Dim stLinkCriteria As Integer
    Dim rsc As DAO.Recordset

    Set rsc = Me.RecordsetClone

    SID = Me.FileNumber.Value
    stLinkCriteria = "[FileNumber]=" & "'" & SID & "'"

    'Check clientdetails table for duplicate FileNumber
    If DCount("FileNumber", "tblClientDetails", stLinkCriteria) > 0 Then

    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning File Number " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation, "Duplicate Information"
    'Go to record of original File Number
    rsc.FindFirst stLinkCriteria
    Me.Bookmark = rsc.Bookmark
    End If

    Set rsc = Nothing
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Dim stLinkCriteria As String
    stLinkCriteria = "[FileNumber]='" & SID & "'"
    Have a nice day!

  3. #3
    Join Date
    Jul 2011
    Posts
    47
    Quote Originally Posted by Sinndho View Post
    Try:
    Code:
    Dim stLinkCriteria As String
    stLinkCriteria = "[FileNumber]='" & SID & "'"

    Hi Sinndho,

    Thanks for the reply, i tried that and then i got another error message:

    Runtime "3464" "data type mismatch in criteria expression"

    The following seems to be the culprit:

    If DCount("FileNumber", "tblClientDetails", stLinkCriteria) > 0 Then
    Any thoughts? Thanks

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try removing the square brackets when assembling the criteria:
    Code:
    stLinkCriteria = "FileNumber='" & SID & "'"
    Have a nice day!

  5. #5
    Join Date
    Jul 2011
    Posts
    47
    Thanks,

    I tried it, but same error message coming up.
    I'm trying to prevent double entry of a particular file number, is there anyway of doing it?

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If FileNumber is a numeric, then you don't use the simple quotes when assembling the criteria:
    Code:
    stLinkCriteria = "FileNumber=" & SID
    Have a nice day!

  7. #7
    Join Date
    Jul 2011
    Posts
    47
    Great, that worked perfectly.

    Thanks Sinndho for the help, really appreciate it!

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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