Dcount Error

Lynn_AccessUser

Registered User.
Local time
Today, 11:43
Joined
Feb 4, 2003
Messages
125
I have a form where a user can add a new record. I am trying to prevent duplicate records from being entered with the following code:

If DCount("[MobileNumber]", "tblMobileNumber", "[MobileNumber]=" & Me.txtMobileNumber) > 0 Then
MsgBox "The mobile number " & Me.txtMobileNumber & " is already assigned."
Cancel = True
Me.Undo
End If

However, I keep getting the following error:

Run-time error '2757':
There was a problem accessing a property or method of the OLE object

I am using almost the exact code on another form without any issues so I can't figure out what is causing the error.

The backend is a SQL 2000 backend with a Access 2000 adp frontend.

Thanks!!!!
 
Are you sure [MobileNumber] is a number field? Most times phonenumbers are text and if it is text then you need to change it to:

DCount("[MobileNumber]", "tblMobileNumber", "[MobileNumber]=""" & Me.txtMobileNumber & """")

Regards
 
Thank you . . . yes you were right the field is a text field.

I did have to change your line of code slightly to:

DCount("[MobileNumber]", "tblMobileNumber", "[MobileNumber]='" & Me.txtMobileNumber & "'")

Otherwise I kept getting the same error.

Thanks for the help!
 
That is OK to....

One can use ".... " & chr(39) & YourText & chr(39)
or: ".... """ & YourText & """" ' Mind the first are 3 and the last are 4 !
or: "... '" & YourText & "'"

they all work...

regards
 

Users who are viewing this thread

Back
Top Bottom