473,395 Members | 1,679 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,395 software developers and data experts.

Error 2467 setting subforms recordsource

6
I currently have a form with a couple text boxes, a button, and an unbound subform. Pressing the button will assemble a SQL string using whatever is in the textboxes and assign the SQL string to the recordsource of the subform.

Unfortunately, doing so results in the run-time error 2467 - "the expression you entered refers to an object that is closed or does not exist."

below is a simple version of my code

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn1_Click()
  2.     strSQL = "SELECT * FROM tbl_SECL_List"
  3.     Me!subtest.Form.RecordSource = strSQL ' error occurs here
  4. End Sub
I've tried to do the same thing, but using a recordset but the same error comes up.

Any suggestions of how to get around this? Or any explanation as to why this is happening?

Any help is greatly appreciated
Jan 7 '08 #1
8 23917
PianoMan64
374 Expert 256MB
Hello,


My first question is, are you going to be entering any data into the subform?

and second, the syntax for the line that you're referring too is incorrect.

it should be:

Expand|Select|Wrap|Line Numbers
  1.      me.subformname.RecordSource = strSQL
  2.  
But you are better off, if you're not going to be entering data, to use a ListControl instead.

Then all you would have to do to refer to it is this:

Expand|Select|Wrap|Line Numbers
  1.      me.listcontrolname.rowsource = strSQL
  2.      me.listcontrolname.requery
  3.      me.repaint
  4.  
Jan 7 '08 #2
fuze
6
There will be no need for data entry, as it's strictly inquiry only.

The syntax is correct as far as I'm aware. Using me.subformname.RecordSource = strSQL brings about an error saying the object does not support that property or method.

A list control would work nicely in code, but it does not provide the fuctionality I need. The users of this tool will be taking the output of these highly dynamic queries and copying their output to excel. I really need something that will display as the datasheet view.
Jan 7 '08 #3
FishVal
2,653 Expert 2GB
Hi, Fuze.

Your initial syntax is quite ok.

Check that [subtest] is the name of subform control (not subform form object).
I recall the same situation with mainform(datasheet)/subform(any) - Access sometimes performs late load "while the object is not visible it is not loaded". Check that the subform form is loaded (you just see it).
Check that form object is accessible - add
Expand|Select|Wrap|Line Numbers
  1. debug.print me!subtest.form.name
  2.  
before faulty string.
Jan 7 '08 #4
fuze
6
Hi, Fuze.

Your initial syntax is quite ok.

Check that [subtest] is the name of subform control (not subform form object).
I recall the same situation with mainform(datasheet)/subform(any) - Access sometimes performs late load "while the object is not visible it is not loaded". Check that the subform form is loaded (you just see it).
Check that form object is accessible - add
Expand|Select|Wrap|Line Numbers
  1. debug.print me!subtest.form.name
  2.  
before faulty string.
Thanks FishVal!

I feel a bit stupid now, but I was referencing the subform form object, not the control. I finally "get" how access goes about referring to everything but I'm a bit disappointed now in what it means for my tool.

Initially, I was just seting the subform control source object to a query object, and using the forms textboxes as variables in my query. This proved to be a problem eventually, because these objects are only accepted in the "WHERE" portion of the clause.

Changing my strSQL with different selection criteria doesn't display properly. It essentially means that I need a different subform for each variant of SQL statement...

Does using recordsets fix this problem?

Update: I tried it with recordsets and it does not solve this inconvenience. Does anyone know a convenient way to change the columns of a form in datasheet view?

Just a shot in the dark, I'm assuming it would be like, for every column name in the recordset, add column to form?
Jan 7 '08 #5
FishVal
2,653 Expert 2GB
Thanks FishVal!

I feel a bit stupid now, but I was referencing the subform form object, not the control. I finally "get" how access goes about referring to everything but I'm a bit disappointed now in what it means for my tool.
I see nothing weird in Access.Form object model.
Really expression like Me![ControlName] returns a member of "Controls" collection returned by the default "Form" class property - "Form.Controls". (Sometimes (if no control found) clever "Form.Controls" property returns reference to a same-named AccessField object which allows read/write linked recordset field).
So you reference Subform control which is a container of "Form" (or not) object.

Initially, I was just seting the subform control source object to a query object, and using the forms textboxes as variables in my query. This proved to be a problem eventually, because these objects are only accepted in the "WHERE" portion of the clause.

Changing my strSQL with different selection criteria doesn't display properly. It essentially means that I need a different subform for each variant of SQL statement...

Does using recordsets fix this problem?

Update: I tried it with recordsets and it does not solve this inconvenience. Does anyone know a convenient way to change the columns of a form in datasheet view?

Just a shot in the dark, I'm assuming it would be like, for every column name in the recordset, add column to form?
Aha. That causes the fault.

Is that really needed to set query as subform's source object?
Why not to design separate form and set it as source object for the subform?
This way you'll be able to get full Form class functionality including RecordSource property as well as design form event handlers in subform's form.
Jan 7 '08 #6
fuze
6
Why not to design separate form and set it as source object for the subform?
Depending on the input, the columns displayed (and possibly the tables queried) will change.

I'm currently looking at about 10 to 15 different datasheet formats I'd need to set up as subforms. Not too much of a problem, just a bit tedious.
Jan 7 '08 #7
fuze
6
OH EM GEE Holy Crap.

This was just a quick test, and it works beautifully as far as simplicity is concerned.

Expand|Select|Wrap|Line Numbers
  1. Dim dbsCurrent As Database
  2. Dim qryDef As QueryDef
  3.  
  4. Public Sub btnSeclAll_Click()
  5.     Set dbsCurrent = CurrentDb
  6.     Set qryDef = dbsCurrent.QueryDefs("qryTest")
  7.     qryDef.SQL = "SELECT * FROM tbl_SECL_ALL;"
  8.     subTest.SourceObject = "Query.qryTest"
  9. End Sub
  10.  
  11. Private Sub btnUser_Click()
  12.     Set dbsCurrent = CurrentDb
  13.     Set qryDef = dbsCurrent.QueryDefs("qryTest")
  14.     qryDef.SQL = "SELECT * FROM tbl_User;"
  15.     subTest.SourceObject = "Query.qryTest"
  16. End Sub
As its written, the button changes the query object that the subform control is bound to, then refreshes it. Based on this I could easily change the query based on the input, and reassign it.

FishVal - Is there any reason why this might be bad? Do you know of an easier or possibly more efficient solution?

Thanks again for all the help - I can't tell you how long I was stuck on that whole control/object mixup...
Jan 7 '08 #8
FishVal
2,653 Expert 2GB
FishVal - Is there any reason why this might be bad? Do you know of an easier or possibly more efficient solution?
That is the question of design style. With form set as source object to your subform control your initial code would work smoothly too.
As for me I prefer to use form as it gives more functionality: events handling, more properties are accessible, more design options etc. Even if I'm not planning to use them at some particular stage of development I just "keep an option"

Though I wouldn't like to force you in your decision.

Good luck,
Fish
Jan 7 '08 #9

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

Similar topics

3
by: Annelies | last post by:
Hi, I want to set the recordsource of a subform to a query with this syntax : Forms!Form_patient!sub75.form.recordsource="MyQueryName" the problem is after typing sub75. I get a list of...
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...
4
by: Gianluca L. Monteleone | last post by:
Hi Folks! I have this strange error that happens after conversion from A97 to AXP (2000-Format). Looks like a bug to me - I've lost 3 days with no result. I use a form with 2 subforms on it,...
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...
1
by: Jimart | last post by:
Hi I Have A Main Form this form has a Subform The SourceObject for the Subform is another subform. I have mastered changing the SourceObject, so that I can have different Subforms appearing...
2
by: Bex | last post by:
Hi All. I'm attempting at the moment to set the recordsource of an unbound subform when i open up it's main form. My view is to have one intial form - called "Search" which has a number of...
5
by: (PeteCresswell) | last post by:
I've got a parent form and three subforms. Two of them work A-OK. For the third one, in the Immediate window: ----------------------------------------- ?Me.subDeal.Name subDeal ...
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...
2
by: qianiqan | last post by:
We have three forms: Main form, SearchForm and its subform SubFormS. Click the button cmdA in MainForm will open the SearchForm. The Search form has a subform SubFormS. The Access database has two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.