A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Run-time Error 2001: You cancelled the previous operation



 
 
Thread Tools Display Modes
  #1  
Old August 2nd, 2005, 02:11 PM
Andy
external usenet poster
 
Posts: n/a
Default Run-time Error 2001: You cancelled the previous operation

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.

  #2  
Old August 2nd, 2005, 03:28 PM
Allan Murphy
external usenet poster
 
Posts: n/a
Default

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 Murphy
Email:

"Andy" wrote in message
ups.com...
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.



  #3  
Old August 2nd, 2005, 04:18 PM
Andy
external usenet poster
 
Posts: n/a
Default

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.

  #4  
Old August 2nd, 2005, 05:14 PM
UpRider
external usenet poster
 
Posts: n/a
Default

If Project1 is a string, try this:

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

HTH
UpRider

"Andy" wrote in message
ups.com...
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.



  #5  
Old August 2nd, 2005, 05:27 PM
Andy
external usenet poster
 
Posts: n/a
Default

Still get the same error! Doh!

  #6  
Old August 2nd, 2005, 05:50 PM
UpRider
external usenet poster
 
Posts: n/a
Default

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

UpRider

"Andy" wrote in message
ps.com...
Still get the same error! Doh!



  #7  
Old August 3rd, 2005, 04:42 AM
Allan Murphy
external usenet poster
 
Posts: n/a
Default

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


--
Allan Murphy
Email:
"Andy" wrote in message
oups.com...
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.



  #8  
Old August 3rd, 2005, 09:05 AM
Andy
external usenet poster
 
Posts: n/a
Default

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.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Question Josh General Discussion 7 March 28th, 2005 11:19 PM
How to reference cancelled meeting time in Updated Meeting notice Debby Calendar 1 December 23rd, 2004 10:51 AM
Use first record found in expression? CASJAS Running & Setting Up Queries 17 July 22nd, 2004 09:21 PM
PREVIOUS MONTH TIME FRAME IN QUERY? Ned Beck Running & Setting Up Queries 2 June 12th, 2004 12:18 AM
Time performance Chart Bull Splat Charts and Charting 6 November 10th, 2003 02:16 PM


All times are GMT +1. The time now is 11:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.