473,657 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to change the Recordsource of an open form from another form using VBA

I have a fairly complex interface screen (form) that is comprised of
several subforms that perform different, but related activities. I am
designing a search/filter form that should be able to change the data
displayed in one or more of the other forms, but I cannot find the way
to change the Recordsource property of the second form from the first.
In a VBA Sub procedure triggered by the Click event of a button on the
search form, I have these bits of code.

'************** ************
'MsgBoxes used purely for my information while coding...
MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource

Parent!RecordLi stings1Panel.Fo rm.DataFieldsPa nel.Form.Record Source =
"Table004_Tasks "

MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource

'************** ************
The first MsgBox correctly displays the name of the current
Recordsource (a query) for the form.
The assignment doesn't seem to work, as the displayed records do not
change on the form.
The second MsgBox doesn't display.

I feel sure that I am missing something terribly obvious, but, try as
I might, I can't figure out what it might be.

Thanks for your help.

Oct 19 '07 #1
2 3478
Several things could be happening here.

The first step will be to temporarily remove any error handling, so you get
to know what's going on. Comment out any error handler in this procedure
(and others if it is called from somewhere else), e.g.:
'On Error ...
Also make sure you have Error Trapping set to:
Break on Unhandled Errors
under:
Tools | Options | General
from the code window.

Chances are, you will now be able to see what's going on. It could be as
simple as that the form is dirty with a record that cannot be saved, so the
attempt to set the RecordSource was not successful. Or it could be more
involved, e.g. you may have triggered an endless loop where the Current
event of that form makes another change to something that re-triggers it
Current event.

You may also need to be aware that when you change the RecordSource of a
subform, Access reassigns the LinkMasterField s/LinkChildFields .

--
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.

"David Haskins" <da*******@gmai l.comwrote in message
news:11******** **************@ e34g2000pro.goo glegroups.com.. .
>I have a fairly complex interface screen (form) that is comprised of
several subforms that perform different, but related activities. I am
designing a search/filter form that should be able to change the data
displayed in one or more of the other forms, but I cannot find the way
to change the Recordsource property of the second form from the first.
In a VBA Sub procedure triggered by the Click event of a button on the
search form, I have these bits of code.

'************** ************
'MsgBoxes used purely for my information while coding...
MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource

Parent!RecordLi stings1Panel.Fo rm.DataFieldsPa nel.Form.Record Source =
"Table004_Tasks "

MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource

'************** ************
The first MsgBox correctly displays the name of the current
Recordsource (a query) for the form.
The assignment doesn't seem to work, as the displayed records do not
change on the form.
The second MsgBox doesn't display.

I feel sure that I am missing something terribly obvious, but, try as
I might, I can't figure out what it might be.

Thanks for your help.
Oct 20 '07 #2
Good tips, I'll try them. Thanks a lot!

-David

On Oct 19, 9:42 pm, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
Several things could be happening here.

The first step will be to temporarily remove any error handling, so you get
to know what's going on. Comment out any error handler in this procedure
(and others if it is called from somewhere else), e.g.:
'On Error ...
Also make sure you have Error Trapping set to:
Break on Unhandled Errors
under:
Tools | Options | General
from the code window.

Chances are, you will now be able to see what's going on. It could be as
simple as that the form is dirty with a record that cannot be saved, so the
attempt to set the RecordSource was not successful. Or it could be more
involved, e.g. you may have triggered an endless loop where the Current
event of that form makes another change to something that re-triggers it
Current event.

You may also need to be aware that when you change the RecordSource of a
subform, Access reassigns the LinkMasterField s/LinkChildFields .

--
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.

"David Haskins" <dahask...@gmai l.comwrote in message

news:11******** **************@ e34g2000pro.goo glegroups.com.. .
I have a fairly complex interface screen (form) that is comprised of
several subforms that perform different, but related activities. I am
designing a search/filter form that should be able to change the data
displayed in one or more of the other forms, but I cannot find the way
to change the Recordsource property of the second form from the first.
In a VBA Sub procedure triggered by the Click event of a button on the
search form, I have these bits of code.
'************** ************
'MsgBoxes used purely for my information while coding...
MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource
Parent!RecordLi stings1Panel.Fo rm.DataFieldsPa nel.Form.Record Source =
"Table004_Tasks "
MsgBox Parent!
RecordListings1 Panel.Form.Data FieldsPanel.For m.RecordSource
'************** ************
The first MsgBox correctly displays the name of the current
Recordsource (a query) for the form.
The assignment doesn't seem to work, as the displayed records do not
change on the form.
The second MsgBox doesn't display.
I feel sure that I am missing something terribly obvious, but, try as
I might, I can't figure out what it might be.
Thanks for your help.- Hide quoted text -

- Show quoted text -

Oct 22 '07 #3

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

Similar topics

2
3895
by: Xiphias | last post by:
Hi, Im trying to change the color of a text box on a report that im printing from a form. On the form I got a check box that has to tricker the color of that textbox on the printed report. If checked color is red else just black. But I dont know how to do it.
2
2622
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the form is opened. After the user selects the contact from an unbound combobox I want the form to be rebound to its recordsource. I tried using form.recordsource = "Contacts" in the afterupdate event of
4
2784
by: ColinWard | last post by:
Hi. I use two different pieces of code to manipulate a recordsource for a form. The first one sets the recordsource to null when the form loads. The second is supposed to display the corresponding record when a name is selected from a combobox. ---Code start---- Private Sub Form_Load() If Not Me.FilterOn Then 'If filter is on, then this form was opened from
19
4090
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
8
10759
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I can't do this in a report as it will prompt me for the parameters, even though they seem to be defined ahead of the recordsource. I have worked around this by opening reports to a bogus recordsource
1
566
by: Simon | last post by:
Dear reader, My SubReport is synchronized with a LinkMasterField and LinkChildField. If I put in the Open event of the SubReport Me.RecordSource = "QueryName" an error pups up. It seems to be that the open event of the SubReport will be activated after each record in the MasterReport. So an error pups up with
5
1980
by: agarwasa2008 | last post by:
Hi, I have a linked table called tbltest and some bounded forms (which add, update, delete records) that were created using that linked table. For some necessary reasons I had to create another linked table called tblComponents and then I bounded the original forms to this new table. I did change the control source: Description (Field name) RowSource Type: Table/Query (which remains the same)
15
40648
beacon
by: beacon | last post by:
Hi everybody, Using Access 2003. I'm trying to dynamically set the record source for the current form and set the control source for a text box to input data to one of three tables. I have a form (frmAddNewUser) that will add users to one of three separate tables (tblDefsAFP, tblDefsMSU, tblDefsWF) based on the selection of an option button from an option group on the same form. I have a textbox (txtNewUser) that accepts the name of...
3
10678
by: Simon van Beek | last post by:
Dear reader, How to change the RecordSource for a subReport. For forms the syntaxes is:
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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
8732
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
8503
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
8605
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1611
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.