473,698 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error setting a subforms recordsource from another form

Bex
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 unbound textboxes. When a user enters in a value into a field and
hits the search button this opens up a results form called "people3"
and sets a subform in this "people3" form - called "results" to show
certain records matching the entered search criteria. The Subform is
initially unbound.

So far i have this code on the search form (only one search field so
far but will be more eventually):

Private Sub cmdFirst_Click( )
On Error GoTo Err_cmdFirst_Cl ick

Dim stDocName As String
Dim stLinkCriteria As String
Dim message
Dim strSQL, strWHERE As String

stDocName = "People3"
strSQL = "SELECT DISTINCTROW People.* FROM People "

If Not IsNull(Me.First Name) Then
strWHERE = " WHERE People.[FirstName] Like " & "'*" &
Me![FirstName] & "*'"
End If
strSQL = strSQL & strWHERE

If Len(strWHERE) = 0 Then
message = MsgBox("No search values entered")
Else
DoCmd.OpenForm stDocName
Forms![People3]![Results].Form.RecordSou rce = strSQL
End If
Exit_cmdFirst_C lick:
Exit Sub

Err_cmdFirst_Cl ick:
MsgBox Err.Description
Resume Exit_cmdFirst_C lick

End Sub

Which is opening up the form but I keep getting the error of: "the
expression you entered refers to an object that is closed or doesn't
exist"

So what am i doing wrong?!?!
Cheers
Bex

Dec 13 '05 #1
2 2390
Could you save your subform with a RecordSource that returns no records:
SELECT People.* FROM People WHERE (False);

That should keep Access happy about the bound controls in the subform.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bex" <be*******@yaho o.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
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 unbound textboxes. When a user enters in a value into a field and
hits the search button this opens up a results form called "people3"
and sets a subform in this "people3" form - called "results" to show
certain records matching the entered search criteria. The Subform is
initially unbound.

So far i have this code on the search form (only one search field so
far but will be more eventually):

Private Sub cmdFirst_Click( )
On Error GoTo Err_cmdFirst_Cl ick

Dim stDocName As String
Dim stLinkCriteria As String
Dim message
Dim strSQL, strWHERE As String

stDocName = "People3"
strSQL = "SELECT DISTINCTROW People.* FROM People "

If Not IsNull(Me.First Name) Then
strWHERE = " WHERE People.[FirstName] Like " & "'*" &
Me![FirstName] & "*'"
End If
strSQL = strSQL & strWHERE

If Len(strWHERE) = 0 Then
message = MsgBox("No search values entered")
Else
DoCmd.OpenForm stDocName
Forms![People3]![Results].Form.RecordSou rce = strSQL
End If
Exit_cmdFirst_C lick:
Exit Sub

Err_cmdFirst_Cl ick:
MsgBox Err.Description
Resume Exit_cmdFirst_C lick

End Sub

Which is opening up the form but I keep getting the error of: "the
expression you entered refers to an object that is closed or doesn't
exist"

So what am i doing wrong?!?!
Cheers
Bex

Dec 14 '05 #2
Bex
Thanks Allen... that seems t have sorted it - or certainly got it to a
point where hopefully i can get the other bits to work! :)

Dec 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2233
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 whose recordsources draw data from the same table. I use a tabbed interface: frmMain has 4 tabs. On each tab there is a form and at least one subform (datasheet). So we're talking at least 5 subform datasheets, on different tabs, all open at...
3
3842
by: Diana Gard | last post by:
Perhaps this is a design flaw, please let me know. I'm using Access 2000. I have a form with a tab control and 5 subforms within those tabs. The forms match with the tables: Client main, Intake, Financial, Fees, Payments, Bills, Bill Line Items. The design works thusly - Client Main relates to Intake. Intake relates to financial. Financial relates Fees, Payments and Bills. Bills relates to Bill Line Items. On the form, I use the...
5
9859
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 Current event. I am using similar code to open each of the subforms successfully -- except for this one case which gives the above error. I have simplified the SQL to its most basic level. It runs just fine as a query. I just can't make it work...
1
1585
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 when I need them BUT what I need to be able to do is to change the RecordSource of the SourceObject Subform from the code behind the Main Form, so I can reuse the SourceObject Subforms
6
1515
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." I really wonder why. I use it in a Form-module, to reference the form itself. The form is used as a subform in another form. Could that be the reason?
9
9692
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 master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
2
3010
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 version db04 and db09. In the old version db04 when I click the command cmdA, it goes first to Form_open of subformS, then goes to the form_open of the SearchForm. Everything is fine. In the new version db09 when I click the command cmdA, it...
1
2108
by: noneedforthis | last post by:
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...
8
23980
by: fuze | last post by:
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 Private Sub btn1_Click() ...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.