Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    186

    Unanswered: DCOUNT a number data type - error 3464

    Hi - I'm getting a run-time error '3464' Data type mismatch on this code that PTLU is a number field. I use it elsewhere for different text fields without error?

    Private Sub PTLU_BeforeUpdate(Cancel As Integer)
    If DCount("*", "PROGOULDACCOUNTS11510", "PTLU = '" & Me.PTLU & "'") > 0 Then
    MsgBox Me.PTLU & " already used!" & vbCrLf & vbCrLf & _
    "Check account number and try again." & vbCrLf & _
    Cancel = True
    Me.Undo
    Me.PTLU.SetFocus


    End If
    End Sub

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if its a number field (AKA column), then why are you encapsualting it with quote marks

    if its a text / string literal / column then use quite marks
    eg:-
    'this is required for text or string columns'
    "if you need to use a quote mark, escape it first using \'"

    if its a a string representation of a date then it must be encapusalted with # and in US or ISO format
    eg:-
    us #mm/dd/yyyy#
    ISO #yyyy/mm/dd#

    using the syntax
    Code:
    if dcount(.....
    is asking for trouble as you are doing no checks on the returning value. if the dcoutn returns null you could have issues. far better to assign the value of the dcount to a variant and then do error checking on the resultant value to make certain your code behaves sanely
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2010
    Posts
    186
    I changed to :
    Private Sub PTLU_BeforeUpdate(Cancel As Integer)
    If DCount("*", "PROGOULDACCOUNTS11510", PTLU = Me.PTLU) > 0 Then
    MsgBox Me.PTLU & " is already used!" & vbCrLf & vbCrLf & _
    "Check account number and try again." & vbCrLf & _
    Cancel = True
    Me.Undo
    Me.PTLU.SetFocus


    End If
    End Sub

    and tested it with duplicate entry for that field.
    I got a message box that says False with an OK button, then a run-time 2108 you must save the field before you execute the GoToControl action , the GoToControl method, or the SetFocus method on Me.PTLU.SetFocus

    What I need it to do is check PTLU(number) if an exact match being entered, msgbox the user that it's already used, clear the entry and put them back in PTLU so they can enter the correct number
    Every entry in this form has a number they are picking up from paperwork, and they will never ever be the same

    I've done this with text, very confused how to do for number field - any direction you can provide is greatly appreciated!

Posting Permissions

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