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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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. |
#3
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
Still get the same error! Doh!
|
#6
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |