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

Runtime error 2001 when trying to change a subform's recordsource

P: 1
I'm a new user of Access/VB and ran in to this nasty wall.
(Access 2003, VB6.3, Windows XP)

Runtime Error 2001: You cancelled the previous operation.

The highlighted line is the one where the recordsource is set to a previously defined SQL statement. What I don't understand is that the code was working perfectly for a long time and it suddenly appeared.

Here's what my program does
- search for items based on the owner/item type etc which is all entered by combo boxes on a form.
- Once OK is clicked, it launches another form, with 2 subforms in it. At that time, based on those combo boxes the recordsource for both subforms are set.
Depending on the combo box options, the SQL statement's Where clause is altered accordingly.
-It looks something like

Expand|Select|Wrap|Line Numbers
  1. Dim A as String
  2. Dim B as String
  3. Dim SQL as String
  4.  
  5. If ComboBoxA = Something Then
  6.     A = " Criteria X"
  7. End If
  8.  
  9. If ComboBoxB = Otherthing Then
  10.     B =" Criteria Y"
  11.  
  12. SQL = Select * from Table Where Criteria Z & A & B & Order by Something
  13.  
  14. SubformRecordsource = SQL 'this line is highlighted
Please help! Thanks!
Jul 27 '07 #1
Share this Question
Share on Google+
1 Reply


puppydogbuddy
Expert 100+
P: 1,923
I'm a new user of Access/VB and ran in to this nasty wall.
(Access 2003, VB6.3, Windows XP)

Runtime Error 2001: You cancelled the previous operation.

The highlighted line is the one where the recordsource is set to a previously defined SQL statement. What I don't understand is that the code was working perfectly for a long time and it suddenly appeared.

Here's what my program does
- search for items based on the owner/item type etc which is all entered by combo boxes on a form.
- Once OK is clicked, it launches another form, with 2 subforms in it. At that time, based on those combo boxes the recordsource for both subforms are set.
Depending on the combo box options, the SQL statement's Where clause is altered accordingly.
-It looks something like

Expand|Select|Wrap|Line Numbers
  1. Dim A as String
  2. Dim B as String
  3. Dim SQL as String
  4.  
  5. If ComboBoxA = Something Then
  6.     A = " Criteria X"
  7. End If
  8.  
  9. If ComboBoxB = Otherthing Then
  10.     B =" Criteria Y"
  11.  
  12. SQL = Select * from Table Where Criteria Z & A & B & Order by Something
  13.  
  14. SubformRecordsource = SQL 'this line is highlighted
Please help! Thanks!
Need more details:
1. are criteria X and Y fields in your table?
2.why the space between left quotes and criteria? A = " Criteria X"
3. what changes did you make before it stopped working?
4. supply sample data for criteria X, sample data for one row of each of your combo boxes.
Aug 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.