subforms SourceObject (1 Viewer)

Massoud

Registered User.
Local time
Today, 13:51
Joined
Jul 11, 2002
Messages
37
Hi again

In my main form, I have a subform which I use to show different forms by it using the
Me.subform1.SourceObject = "form1"

Inside the form1 , by running some procedures, it is required to open form2. And form2 is again to be opened in place of subform1 in the main form.
So again I write:
Me.parent!subform1.SourceObject = "form2"
This works ok by showing form2 instead of form1.
But something is wrong. For example when I opened form2 seperately, I could add records or edit the text boxes' contents. but now everything seems locked!
What is to be done?
 

OlcayM

Registered User.
Local time
Today, 15:51
Joined
Oct 30, 2007
Messages
47
Hi,

I simulated what you have done, adn seems there should be no problem. I noticed something in your code. It may not be wrong but???
Me.subform1.SourceObject = "form1" line should read
Me!subform1.SourceObject = "form1"
Me.parent!subform1.SourceObject = "form2" line should read
parent!subform1.SourceObject = "form2"
may be your problem comes from there. or may be on form1's event, you rae still trying to do something after you changed to form2.

Olcaym
 

Massoud

Registered User.
Local time
Today, 13:51
Joined
Jul 11, 2002
Messages
37
Thanks OlcayM

Actually the problem is not with opening of form1 or form2 in the main form.
To describe the problem better: form1 has a subform1 in it (datasheet) with a specific record source. It opens up and the subform1 also shows all the records I need. When we push a button in form1, we need to switch to form2 which also has a subform2 (again data sheet) in it . And this is were the problem is noticed: The form2 is opened (in place of form1 in the main form) however, the subform2 does not show any records at all. Maybe I'm not sending the parameters to form2 in a proper way, but how should it be. Also form2 itself has some unbounded textboxes in it which they are also locked!
 

ajetrumpet

Banned
Local time
Today, 07:51
Joined
Jun 22, 2007
Messages
5,638
I'll join in here too...
Can you elaborate a bit more on the subforms? Specifically, to these questions...

1) You have 2 sets of parent/child nested forms (form1/subform1, form2/subform2)??
2) You have a main form that holds both of these sets??
3) Are both of the sets just nested inside the main form, or can there be one set nested inside the other set??
4) Why are you changing the source object?? Is it necessary?? What is the purpose. If each form is an object of its own, so most of the time there is no need for this.
5) Do you have a picture of the form that people can look at?? It seems to be a little bit difficult to read and digest...
 

Massoud

Registered User.
Local time
Today, 13:51
Joined
Jul 11, 2002
Messages
37
Hi ajetrumpet, welcome aboard.
The idea is that since the program will have many forms to be opened and viewed, and it is required to surf between forms back and forth, we want to avoid to have too many opened forms on top of one another. So I decided that I will have only one main form opened and it has a subform object which I've called it workspace and by changing workspace.sourceobject to various forms, the required tasks of the program are fulfilled. The task forms are not nested inside one another. only as I said before we might call form2 from form1 .... . I've also found a way to keep track of my movement so I can step back to the main form and also when one task is done, we have to return to the form that requested for that task.
The problem I mentioned above is solved. I had set the allow edit and allow addition ... of the main form to No.
Now I'm thinking for another problem. Since the forms call each other, they have to send special parameters also to set the conditions of the task.
If I were using the doCmd way, I would easily send the parameters using the openArgs variable. But now I'm only changing the sourceObject property. Therefore I've put some text boxes on the main form and by setting the values of these textboxes by the caller form, the called form will be able to know about the parameters. (I will set the visibility of these text boxes on the main form to False)
Is there any better way? Since the number of these text boxes is growing rapidly.

Thanks again for your intrest.
 

GolferGuy

Registered User.
Local time
Today, 05:51
Joined
Nov 5, 2007
Messages
175
Massoud,
I have been using this method (one subform control, many forms to put into it) for about 11 years now. Works great! In order to pass parameters to a form that is being opened in this one subform control, I have a form, which I call "frmUtility" that I open when the database is opened, and it stays open, and hidden, the entire time the database is open. Whatever global variables need to be available to these forms as they are opened within the subform control, I place a text box on this frmUtility so it is available to be read by the new form being opened in the subform control. This method has worked like a charm!
 

Massoud

Registered User.
Local time
Today, 13:51
Joined
Jul 11, 2002
Messages
37
Thanks GolferGuy.
It is very good to know one is on the right path, especially from an expert.
How about using Public variables that are available to all forms and queries instead of your frmUtility text boxes. I've now tested both methods and don't see any preferences of either way.
 

GolferGuy

Registered User.
Local time
Today, 05:51
Joined
Nov 5, 2007
Messages
175
Public variables are very handy, but I have found the hidden form to be more useful for me, and here are the reasons, all of which I have found make writting the code for the database easier and more convient.
1. When the program code crashes, and you must Stop the code, you will lose all your global variables. The hidden form will continue to have all the variable data you put there.
2. When you want to use a global variable as a filter for a form, or a criteria within a query, you will have to write a function to return that variable as queries and form filters can not use global VBA variables, they can only use functions. For a form filter or the criteria within a query, you can use Forms!frmUtility!MyNeededValue without having to write a function.
3. At any point, you can look at all your global variable values if you ever need to.
4. I have found frmUtility wonderful when working on a report that has filter type of parameters, such as From and To dates, or a Region Code, or whatever. I don't have to keep opening the parameter entry form and filling out the parameters again. They are all stored within frmUtility, it is open, so all I have to do for report testing is just double click on the report, or select PrintPreview mode.

If I think of any more reasons, I'll try to post them too. I feel that the frmUtility concept has saved me 50 to 100 hours per year, and I've been using it for about 15 years now.
 

boblarson

Smeghead
Local time
Today, 05:51
Joined
Jan 12, 2001
Messages
32,059
Public variables are very handy, but I have found the hidden form to be more useful for me...
Pat Hartman, former Access MVP, has said similar things in the past.

I have to admit that I haven't used that method, but am seriously considering it as it does seem a little more robust for many reasons.
 

GolferGuy

Registered User.
Local time
Today, 05:51
Joined
Nov 5, 2007
Messages
175
Pat Hartman, former Access MVP, has said similar things in the past.
Thanks Bob, Pat is the first person I have heard of that might do this same/similar thing. Actually feels good to not be a loner.:)
 

pondlife

Registered User.
Local time
Today, 13:51
Joined
Apr 27, 2007
Messages
49
why not have both form 1 and form 2 open as subforms simultaneously and just change the .visible property of each according to the one you want to see/use.
 

boblarson

Smeghead
Local time
Today, 05:51
Joined
Jan 12, 2001
Messages
32,059
why not have both form 1 and form 2 open as subforms simultaneously and just change the .visible property of each according to the one you want to see/use.

Depending on the recordsources this can cause severe slow loading. Usually it is a good thing, unless you have very small recordsets, to load only when you need it. Opening each subform will open a separate recordset, so opening both at once can potentially slow things way down for the user.
 

GolferGuy

Registered User.
Local time
Today, 05:51
Joined
Nov 5, 2007
Messages
175
If you onlyhave a couple of subforms, YES, by all means. But, in my applications, I have quite a few forms, upwards of 80 in one of my apps. It would take a couple of minutes to open all those forms if they were all in their own subform Controls, but hidden. So, in simple terms, one subform control and many forms to go into that one subform control, each one at it's own time, is to keep the user from having to wait when the main form opens. I have found the cut-off to be between 5 and 10 forms before the wait is very noticeable.
 

Users who are viewing this thread

Top Bottom