Run-time Error 2001: You cancelled the previous operation

  • Thread starter Thread starter Andy
  • Start date Start date
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.
 
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.
 
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.
 
If Project1 is a string, try this:

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

HTH
UpRider
 
Back
Top