Run-time Error 2001: You cancelled the previous operation

A

Andy

Hi,

I am using Access 2003 and am building an database in Access 2000
format. I have created one table "Project Information" which holds a
number of attributes which can be set to true or false to indicate if
these attributes are to be used.

I have another table called requirements where these attributes can be
given values. I am trying to valildate on my form that values are
entered for attributes when the attribute is set to True on the Project
Information table. The initial code I have done to try this out for
just one attribute is as follows:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DLookup("[Compliance Level]", "Project Information",
"[ProjectID] = Project1") = True Then
If IsNull(Me.Compliance_Level) Or Me.Compliance_Level = "" Then
MsgBox "Must have an entry here"
Me.Compliance_Level.SetFocus
Cancel = True
Else
MsgBox "Not Null"
End If
End If
End Sub

I have the "ProjectID" hard coded at the moment while I test things out
and it is a Text field.

When I enter Debug it is highlighting the DLookup line. I'm a bit of a
newbie to Access. Could anyone please tell me where I am going wrong?

Thanks,

Andy.
 
A

Allan Murphy

Andy

Try

dim check_project as string

check_project = DLookup("[Compliance Level]", "Project Information",
"[ProjectID] = Project1")

if check_Project = True then
rest of your code

I found that you cannot Dlookup in the format that you used it must be
assign to a variable or filed name etc.
 
A

Andy

Allan,

Many thanks for your suggestion, however, I have changed the code as
you suggested and it still produces the same error. Code below:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim check_project As String
check_project = DLookup("[Compliance Level]", "Project
Information", "[ProjectID] = Project1")
If check_project = True Then
If IsNull(Me.Compliance_Level) Or Me.Compliance_Level = "" Then
MsgBox "Please enter the Compliance Level"
Me.Compliance_Level.SetFocus
Cancel = True
Else
MsgBox "Not Null"
End If
End If
End Sub

Any more thoughts?

Andy.
 
U

UpRider

If Project1 is a string, try this:

If DLookup("[Compliance Level]", "Project Information", "[ProjectID=" &
Chr$(39) & Project1 & Chr$(39)) = True

HTH
UpRider
 
U

UpRider

Just noticed that "Project Information" should be in square brackets....
"[Project Information]"

UpRider
 
A

Allan Murphy

Andy

As Project1 is a text box,so the dlookup must be changed
I have added a docmd.cancelevent


Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim check_project As String

check_project = DLookup("[Compliance Level]", "Project Information",
"[ProjectID] = " & me! Project1)
If check_project = True Then
If IsNull(Me.Compliance_Level) Or Me.Compliance_Level = "" Then
docmd.cancelevent
MsgBox "Please enter the Compliance Level"
Me.Compliance_Level.SetFocus
Else
MsgBox "Not Null"
End If ' null test

End If ' project true

End Sub
 
A

Andy

Allan,

Project1 wasn't a text box, it was just a hard coded string. However,
to avoid any possible confusion, I have made it a text box so that I
could use the code you specified. Unfortunately, it still produces the
same error. The new code is below. I put sqaure brackets around
"Project Information" on the Dlookup line as suggested by UpRider, but
it produces the same error with or without them!

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim check_project As String
check_project = DLookup("[Compliance Level]", "[Project
Information]", "[ProjectID] = " & Me!ProjectID)
If check_project = True Then
If IsNull(Me.Compliance_Level) Or Me.Compliance_Level = "" Then
DoCmd.CancelEvent
MsgBox "Please enter the Compliance Level"
Me.Compliance_Level.SetFocus
Cancel = True
Else
MsgBox "Not Null"
End If ' Null Test
End If ' Project True
End Sub

Thanks for all your help as being a relative Access newbie, I can't
understand at all why this shouldn't work! Cheers.

Andy.
 
Top