473,418 Members | 2,085 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,418 software developers and data experts.

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_Click

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.FirstName) 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.RecordSource = strSQL
End If
Exit_cmdFirst_Click:
Exit Sub

Err_cmdFirst_Click:
MsgBox Err.Description
Resume Exit_cmdFirst_Click

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 2380
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*******@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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_Click

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.FirstName) 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.RecordSource = strSQL
End If
Exit_cmdFirst_Click:
Exit Sub

Err_cmdFirst_Click:
MsgBox Err.Description
Resume Exit_cmdFirst_Click

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
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...
3
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,...
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...
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...
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...
1
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...
8
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...
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...
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...
0
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...

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.