DCOUNT for number field

Foskbou

New member
Local time
Yesterday, 19:26
Joined
Dec 17, 2010
Messages
2
I have this code in my form to check record source table PGACCOUNTS11510 for a duplicate entry in PTLU, which is a number - this number is entered from paperwork, which is always unique
Here, if they duplicate it, user should get a message and is returned to the field to enter a different number

tested not getting expected results:
Private Sub PTLU_BeforeUpdate(Cancel As Integer)
If DCount("*", "PGACCOUNTS11510", 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

This is triggering every time, if its a duplicate or not, with a msg box False
When I ok that msg I return to the form, and then a run-time 2108 you must save the field before you execute the GoToControl action , the GoToControl method, or the SetFocus method
The form goes blank and the record is not saved

Any ideas on where I went wrong?
 
The WHERE part in your DCOUNT is always true, the way you have written it, so the thing probably returns the total record count every time. Lookup DCOUNT documentation to see how to write it.
 

Users who are viewing this thread

Back
Top Bottom