473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 2096
puppydogbuddy
1,923 Expert 1GB
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

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

Similar topics

4
by: deko | last post by:
RE: "Object Invalid or No Longer Set" errors I've had an angelic visitation and the revelation is that my problem, in essence, is due to the fact that I have multiple forms open at the same time...
2
by: Michelle | last post by:
Hi all I have used knowledge base article 112747 to improve my subforms performance. I am using Access 97. I have a main form where i put an extra textbox which concatenated TeamID WeekNum...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
5
by: Lyn | last post by:
Hi, this has been driving me nuts. I'm on Office 2003 SP1, Win XP SP1. I am opening a form with a number of subforms based on various tables. The subforms are populated via the main form's...
6
by: olaf | last post by:
Hi! When using the "me." keyword (for ex. me.FilterOn = True), I sometimes (not always) get the error message: "The expression yuo entered refers to an object that is closed or doesn't exist."...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
6
by: Widge | last post by:
I've been using code similar to this: Option Compare Database Private Sub Form_Open(Cancel As Integer) SetFilter
3
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
3
by: gmazza via AccessMonster.com | last post by:
Hi there, I am a novice at Access programming but I am flustered by this error and don't understand what I am doing wrong, any help is appreciated. Here is my code: Sub SetFilter() Dim LSQL ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.