By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

What operation have I cancelled?

P: n/a
I am making my first attempt at a project using VBA and have hit a problem. I
can find nothing to help in any book. My code is generating a message "Runtime
error 2001 You canceled the previous operation."

I created a relatively simple form, which allows the user to view and add
details of patients. I put a filter option control on the form so that the
patients could be filtered to those allocated to a chosen member of staff. This
worked perfectly.

Afterwards, I created various reports and, finally, another form to select the
particular report required with another filter option control to limit the
selected report to the patients of a particular member of staff. This works as
expected. I stopped for the day, well content.

The next time I opened the project, I went to the first form and immediately
received the error message mentioned when I tried to impose the filter to the
chosen member of staff. What operation have I cancelled? At this stage, I have
not run any other code. Only removing the second form and its code makes the
first form work again without generating the error.

It seems that there is no "help" available from the program.
I would appreciate any assistance.

John Martin
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I often get this error message when I use an aggregate function (e.g.
dcount, dlookup, etc....)

It really does not make sense. So the error message will not give you to
many clues.

Therefore, you need to find out when it happens. Do you know how to debug
code (do you have any???).

- Nicolaas
Nov 13 '05 #2

P: n/a
Hi John,

The cause of this problem is that you execute code to open the report but jump
to some other code before the report opens. Typically this other code is in the
OnOpen event of the report where you cancel opening the report. The cure to the
problem is to put the following line of code in the first code where you open
the report. Put it as the first line of code in your procedure:
On Error Resume Next

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"John Martin" <jh*****@aol.com> wrote in message
news:20***************************@mb-m21.aol.com...
I am making my first attempt at a project using VBA and have hit a problem. I
can find nothing to help in any book. My code is generating a message "Runtime
error 2001 You canceled the previous operation."

I created a relatively simple form, which allows the user to view and add
details of patients. I put a filter option control on the form so that the
patients could be filtered to those allocated to a chosen member of staff. This worked perfectly.

Afterwards, I created various reports and, finally, another form to select the
particular report required with another filter option control to limit the
selected report to the patients of a particular member of staff. This works as
expected. I stopped for the day, well content.

The next time I opened the project, I went to the first form and immediately
received the error message mentioned when I tried to impose the filter to the
chosen member of staff. What operation have I cancelled? At this stage, I have
not run any other code. Only removing the second form and its code makes the
first form work again without generating the error.

It seems that there is no "help" available from the program.
I would appreciate any assistance.

John Martin

Nov 13 '05 #3

P: n/a
There's no such function in my code. I do have some. Please tell me what's
wrong with this:

Option Compare Database
Option Explicit
Dim pstrReportName As String
Dim pstrFilter As String

Private Sub ExitReportFilterButton_Click()
On Error GoTo Err_ExitReportFilterButton_Click

DoCmd.Close acForm, "Report Filter Form"

Exit_ExitReportFilterButton_Click:
Exit Sub

Err_ExitReportFilterButton_Click:
MsgBox Err.Description
Resume Exit_ExitReportFilterButton_Click

End Sub

Private Sub ProceedReportButton_Click()
' On Error GoTo Err_ProceedReportButton_Click
On Error Resume Next

DoCmd.OpenReport pstrReportName, acViewPreview, , pstrFilter
DoCmd.Close acForm, "Report Filter Form"

Exit_ProceedReportButton_Click:
Exit Sub

Err_ProceedReportButton_Click:
MsgBox Err.Description
Resume Exit_ProceedReportButton_Click

End Sub

Private Sub ReportSelecterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next

Select Case ReportSelecterOption
Case 1
pstrReportName = "Patients (Alphabetical)"
Case 2
pstrReportName = "Patients (By Case Open for)"
Case 3
pstrReportName = "Patients (By case open to & case open for)"
Case 4
pstrReportName = "Patients by registration date"
Case 5
pstrReportName = "Patients (by case open to)"
End Select
End Sub
Private Sub ReportFilterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next
Select Case ReportFilterOption
Case 2 'KM selected
pstrFilter = "[case open to] = 2"
Case 3 'CW selected
pstrFilter = "[case open to] = 3"
Case 4 'HvL selected
pstrFilter = "[case open to] = 1"
Case 5 'Unallocated selected
pstrFilter = "[case open to] = 4"
Case Else 'no value for intFilter if All selected
pstrFilter = ""
End Select
End Sub

Nov 13 '05 #4

P: n/a
I had a look through your code.

It looks fine at first, but it definitely could have many problems.

The way to solve a problem like this is to put in some breakpoints to work
out where things go wrong.

Also put a ' before each error handler. In that way, your code will break
when the error occurs.

Once you are satisfied that it works then you take the apostrophes back out.

Once you work out where the problem occurs, you can put in a few breakpoints
and see, for example, what values your variables have (move your mouse over
them).

Let me know how you get on.

- Nicolaas
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.