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

Problem with programatically changing subform properties

63
I have a parent form bound to a recordsource and several controls are bound to fields in that recordsource. There are also several unbound controls that are used to display various data in a subform.

It's setup to display "Form A" in the subform control if a selection is made on "List A" (unbound) in the parent form. "Form A" has as its recordsource a Query object which uses the value of "List A" as criteria.

Similarly, if the user clicks a selection on "List B", the subform control's sourceobject changes to "Form B" in the same manner.

If I set the subform's sourceobject manually to "Form B", for example, it will display the data fine. But when the sourceobject is being programatically changed using VBA, then the queries won't retrieve the data.

If I clear out the PARENT form's recordsource, then it works as it's supposed to, but then all the other BOUND controls don't work.

Am I missing something? Any help is much appreciated. Thank you.
Apr 29 '09 #1
19 4937
DonRayner
489 Expert 256MB
Hi Postman, can you post back with the code that you are currently using so that we can take a look at it.

Don
Apr 30 '09 #2
NeoPa
32,556 Expert Mod 16PB
As Don implies, it's hard to say what's wrong without knowing what you have.

In case it helps, check out Referring to Items on a Sub-Form.
Apr 30 '09 #3
postman
63
Here's the code that's run when the listbox in the parent form is clicked.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListA_Click()
  2. With Me.subformControl
  3.  
  4.      If .SourceObject <> "FormA" Then .SourceObject = "FormA"
  5.      .Form.Requery
  6.  
  7. End With
  8. End Sub
It works fine, unless the parent form is bound to a recordsource. Not sure why that would interfere, since the listboxes are unbound.
Apr 30 '09 #4
FishVal
2,653 Expert 2GB
Check whether Master/Child fields settings are relevant for both FormA and FormB.
Apr 30 '09 #5
ChipR
1,287 Expert 1GB
Also, verify that the Data Entry property on the Data tab is set to No. Can't think of anything else at the moment.
Apr 30 '09 #6
NeoPa
32,556 Expert Mod 16PB
@FishVal
Now I've had a chance to look at this in more detail I understand the question a lot better.

With my better understanding I would certainly say that Fish is on the right lines. Can you let us know if this has thrown any light on the matter?

It's hard with a question like this to be able to point you in the right direction as there are so many variables we just don't know. It's the sort of question that is easier handled directly (hands-on).
Apr 30 '09 #7
postman
63
@FishVal
The only place I see the settings for "Link Master Fields" and "Link Child Fields" is on the subform control itself, not the subforms.

Both settings are blank. I also tried manually setting both to blank using this code:

Expand|Select|Wrap|Line Numbers
  1. With Me.subformControl
  2.     .LinkChildFields = ""
  3.     .LinkMasterFields = ""
  4.     .Form.Requery
  5. End With
Still same result.

And the "DataEntry" property is set to 'No' on both subforms.
Apr 30 '09 #8
DonRayner
489 Expert 256MB
Hmmm, I just whipped up some quick forms using your criteria and code and it seamed to work fine. I then added a query as the record-source to each of the subforms with the criteria based on the appropriate list-boxes, then started noticing your problem.

I fixed it up by setting the subforms record-source directly from the listbox click event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ListA_Click()
  2. Dim stSQL As String
  3. stSQL = "SELECT Table1A.* FROM Table1A WHERE (((Table1A.Field1)=" & Me.ListA & "));"
  4. With Me.subformControl
  5.  
  6.      If .SourceObject <> "FormA" Then .SourceObject = "FormA"
  7.      .Form.RecordSource = stSQL
  8.      .Form.Requery
  9.  
  10. End With
  11. End Sub
This is based on a test db that I use when I need to quickly test something so you will have to change the table and field names. Also the I was using numbers in my listbox. If you are using text you will have to change the SQL to include the quotations.
Apr 30 '09 #9
NeoPa
32,556 Expert Mod 16PB
Nice solution Don.

I would just make some changes (again sorry) for reasons I'll explain.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListA_Click()
  2. Dim stSQL As String
  3. With Me.subformControl
  4.     If .SourceObject <> "FormA" Then
  5.         stSQL = "SELECT * " & _
  6.                 "FROM Table1A " & _
  7.                 "WHERE [Field1]=" & Me.ListA
  8.         .SourceObject = "FormA"
  9.         .Form.RecordSource = stSQL
  10.     End If
  11. End With
  12. End Sub
Everything would be dependent on .SourceObject <> "FormA".
The SQL is mainly changed for layout here, but I also removed redundant table qualifiers and parentheses (often added by Access unnecessarily).
Lastly, if the RecordSource is changed in code, the .Requery is redundant as it gets the data anyway.

I should add that this is not to criticise, as the original is perfectly working code, I just wanted to introduce some considerations.
May 1 '09 #10
DonRayner
489 Expert 256MB
@NeoPa
No need to be sorry NeoPa, change away. I did just quickly grab the SQL out of the query that the subform was based on (lazy this evening), I also should have cleaned up the code after I found that my patch to the OP's code worked but I didn't. Thanks for cleaning it up form me.
May 1 '09 #11
NeoPa
32,556 Expert Mod 16PB
@DonRayner
Nothing wrong with that. No reason to expect any more.
@DonRayner
Actually, I can't agree with that.

I'd hate to put anyone off from posting anything helpful simply because they're too busy to tidy it all up perfectly. It illustrated the point nicely.

It's not like you're expecting someone to decipher your question because you couldn't be bothered to ask it clearly. Now that's a problem ;)
May 1 '09 #12
Denburt
1,356 Expert 1GB
I'm not 100% (only 99.9) sure and unfortunately I'm a bit busy to check but if you don't have the Child/Master fields set then this would cause the problem you are having. If you want the parent (Main) form to be bound to a recordset then you will need to correlate the Child/Master Fields appropriately even if you did this in VBA when you change subforms.
Expand|Select|Wrap|Line Numbers
  1. ctl.LinkChildFields = srcFld(0) & ";" & srcFld(1)
  2. ctl.LinkMasterFields = srcFld(0) & ";" & srcFld(1)
@postman
May 1 '09 #13
postman
63
@Denburt
Even if the subform has no relation to the recordset of the parent form?
May 1 '09 #14
Denburt
1,356 Expert 1GB
O.K. I just checked ignore my previous post, that shouldn't be a factor I just ran a few quick tests and after rereading your issue I have tried to duplicate it and I seem to be having no problems changing the sub form control from one to another as you described.

It sounds like something may be happening in your code that is interfering with the choice you are making, perhaps something in the oncurrent event or somewhere along the way. The only other thing I can think of is that the form may be corrupt. Try recreating the form and see if it is still an issue.
May 1 '09 #15
ChipR
1,287 Expert 1GB
Did Don's suggestion of manually setting the Form.RecordSource after the .SourceObject and then .Requery not work for you?
May 1 '09 #16
Denburt
1,356 Expert 1GB
Oh and looking this over again are you sure that when you set your query to retrieve the values from the listbox that you are designating quotes for text and no quotes for numbers # for dates etc.?
May 1 '09 #17
postman
63
Sorry, I'm just getting opportunity to get back to this project today....
Don, I will try your suggestion now and post the results soon.

Thank you for all your assistance. It is much appreciated!
May 5 '09 #18
postman
63
It's working now...using the original setup I had (see post #4). In the course of implementing Don's solution, I found the root problem:
If both the subform and the parent form's recordsources are pulling data from their respective tables including "ID" fields that are named the same, the subform will not display data.
NOTE: This only happens when programatically switching the subform control's "Sourceobject".
Here are the details....

The 3 tables all have an ID field with the same name "ID" (it's an autonumber field & Primary key on all 3 tables). We'll call them "ParentForm_Tbl", "FormA_Tbl", "FormB_Tbl".

The Parent form's recordsource was set to the table "ParentForm_Tbl".

The Query for the subform's recordsource pulls data from "FormA_Tbl" (or "B"). I had the "ID" field as the criteria (WHERE statement), but also included in the SELECT statement as a field to retrieve data from. I removed it from the SELECT statement, then all worked fine!

So I did some more testing and put it back into the SELECT statement, but renamed the "ID" field in the Subform table to something different (e.g. "IDformA") than the ID field in the Parentform table. It also worked fine!

I don't know why this is happening. I tried recreating the problem by renaming other fields to have the same name in both the Parentform table and Subform tables, but did not have any problem. Maybe it has something to do with the ID fields all being Primary keys.

So, this issue appears solved. I don't understand the problem, but it's kind of a moot point now, I guess.

Thanks again for all your assistance. I'm sure I would not have found the solution without your help!
May 5 '09 #19
NeoPa
32,556 Expert Mod 16PB
Wow!

Nice post Postie :)

It's great to have such a complicated situation properly answered.
May 6 '09 #20

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

Similar topics

1
by: Fred Chen | last post by:
Hi, I've created a custom component. I want one of the properties of my custom component to be the output file name which is found in project properties. I know that I can get this by writing...
0
by: Robert-Paul | last post by:
Hi there. I have a problem after changing the assembly name of a class library. I have two projects in one solution: - a Windows application (.exe) - Class Library. There is a references...
1
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change...
8
by: Rak | last post by:
I am looking for a way to programatically change the .net version of the virtual directory that I am creating within a aspx page. As part of creating a new customer in my asp.net 2 application, it...
2
nabh4u
by: nabh4u | last post by:
hi friends, i have a program where i have to sort a double linked list using merge sort. i am having problem with changing the pointers of the list, like the previous and the next pointers of a...
6
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I've encountered a problem using gettext with properties while using a Python interpreter. Here's a simple program that illustrate the problem. ============== # i18n_test.py: test of gettext &...
0
by: sumithrak | last post by:
Hello, I have a problem with changing the paper size for the defaut net work printer in vb 6.0. Need help...... thank you
0
by: genesaika | last post by:
hello i am looking at changing the properties of a select line of output when a certain objective is true. i have built a menu type of area that holds information and when the information gets too...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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.