Help with Runtime error 2001 (1 Viewer)

nir

New member
Local time
Today, 08:03
Joined
Oct 27, 2005
Messages
5
hi

I am building an application in which the user has to enter a ProjectName that is a key (no duplicate). For that I wish to validate the entered value in the Field level (I thank everybody that bothered to respond to my previous thread). I've wrote this piece of code :

_________________________________________________________
Private Sub ProjectName_BeforeUpdate(Cancel As Integer)

Dim strFilter As String
Dim strResult As String

strFilter = "ProjectName = " & Me.ProjectName
strResult = DLookUp("ProjectName", "Projects", strFilter)

If strResult <> Null Then
MsgBox("Name already exist")
Cancel = True
End If
End Sub
_________________________________________________________

While testing the code, I got a Runtime error 2001, specifying that I've canceled previous action ??? and the debugger points to the line containing the DLookUp Function.

Note - I opened the form with acFormAdd.


Thanks in advance for any assistance.
 
Last edited:

RuralGuy

AWF VIP
Local time
Yesterday, 23:03
Joined
Jul 2, 2005
Messages
13,826
I see several things, try:
Code:
strFilter = "[ProjectName] = '" & Me.ProjectName & "'"
If Not IsNull(DLookUp("[ProjectName]", "Projects", strFilter)) Then
   MsgBox("Name already exist")
   Cancel = True
End If
I don't think strings like having Nulls shoved into them. And please note the []'s I have added to your code.
 

RV

Registered User.
Local time
Today, 06:03
Joined
Feb 8, 2002
Messages
1,115
Code:
Private Sub ProjectName_BeforeUpdate(Cancel As Integer)

Dim strFilter As String

strFilter = "ProjectName = " & Me.ProjectName

If DCount ("*", "Projects", strFilter) > 0 Then
MsgBox("Name already exist")
Cancel = True
End If
End Sub

RV
 

nir

New member
Local time
Today, 08:03
Joined
Oct 27, 2005
Messages
5
Thanks

Thanks guys. It's working nicely. :)
 

Users who are viewing this thread

Top Bottom