Calling a specific control

J

Jan Il

Hi all -

I have two questions. I have a series of functions where I simply want to;

1. Contact/call a specific control on a specific form.
1. From a specific form when it is opened.
3. Display the name of the contacting/calling form in the specific control
Caption when the specific form it is on is opened.

All controls on all the end/target forms have the same generic names. I have
been playing with this for some time, and trying to figure out how to get
each control to call the name of the related form into it when the
end/target form is opened, when there are various forms involved in the
process of reaching the end/target form and will vary from function to
function. I have given
considerable thought to this process, and it occurs to me that trying to
have the controls call a specific form from among all the various forms,
which can not be determined until the form is opened, is actually backwards.

It seems to me that the process should be the other way around, from the
/form/ to the control. I may be all wet here in my thinking, and it won't be
the first time, but, it seems like it would make more sense. Here's why;

Since the controls on the forms will all be the same generic series of
names, it will be much easier and reasonable to have the various primary
forms contact a specific control in an end/target form, as that control name
will always be known. Each form will always have it's own target/end form
control, the control it will be displayed in when the target/end form is
open. Each form then could be coded to contact their specific control on a
specific form such as;

Form: Main Menu to Form: Wayside Inspection Form control lblControl1. Then
when the Wayside Inspection Form is subsequently opened at the end of the
navigation process, the name of the form Main Manu will be displayed in the
control lblControl1. The next form in the navigation series, Wayside
Inspection Menu would then contact Form: Wayside Inspection Form control
lblControl2, and when the form is opened, the name Wayside Inspection Menu
would be displayed in the control lblControl2.

Question 1: Can this be done?
Question 2: What would be the best method to accomplish this function, Macro
or VBA?

I would truly appreciate any suggestions or references. Hopefully, I have
explained it in a manner that will make some sense. :)

Best regards,
Jan
 
G

Gerald Stanley

The passing of information from Calling Form (or Calling
Menu) to Called Form is do-able through VBA. I can offer
two suggestions for you to practise with:

1. Accessing the controls once the form is loaded.
You can manipulate the controls on any 'loaded' form
through the Forms Collection.
e.g. In your Main form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form"
Forms![Wayside Inspection Form]!lblControl1.Caption = "Main
Form"

2. Passing the Form Name through as an opening argument
e.g In your Main Form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form"

and in your Form_Load() method of the Wayside Inspection
Form, write something along the lines of

lblControl1.Caption = OpenArgs

Hope That Helps
Gerald Stanley MCSD
 
J

Jan Il

Hi Gerald!
The passing of information from Calling Form (or Calling
Menu) to Called Form is do-able through VBA. I can offer
two suggestions for you to practise with:

1. Accessing the controls once the form is loaded.
You can manipulate the controls on any 'loaded' form
through the Forms Collection.
e.g. In your Main form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form"
Forms![Wayside Inspection Form]!lblControl1.Caption = "Main
Form"

2. Passing the Form Name through as an opening argument
e.g In your Main Form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form"

and in your Form_Load() method of the Wayside Inspection
Form, write something along the lines of

lblControl1.Caption = OpenArgs

Yes, this is in the area of what I am hoping to do. Your second suggestion
would seem to be very much how I see the process working, as the target/end
form will not be opened until all the other forms in the process have been
opened. So, the control will have to be called pre-opening as opposed to
post-opening. Therefore, when the end form is opened, all the controls would
then display the names of their respective forms in the navigation process.

If I understand this clearly; each form in the navigation process leading up
to the opening of the end/target form, can have this same code in each of
them to call their respective control on the end form, by just changing the
lblControl name. This because, they will all be targeting the same end form,
Wayside Inspection Form, just a different control name. Is this correct?
Thus, the same control code can be placed in lblControl2 for the next form
in the navigation line? Is this correct?

Thank you so for very much for this information. I'll go try it and see how
I do. ;-)

Best regards,
Jan :)
 
J

Jan Il

Hi Gerald,
The passing of information from Calling Form (or Calling
Menu) to Called Form is do-able through VBA. I can offer
two suggestions for you to practise with:

1. Accessing the controls once the form is loaded.
You can manipulate the controls on any 'loaded' form
through the Forms Collection.
e.g. In your Main form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form"
Forms![Wayside Inspection Form]!lblControl1.Caption = "Main
Form"

2. Passing the Form Name through as an opening argument
e.g In your Main Form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form"

and in your Form_Load() method of the Wayside Inspection
Form, write something along the lines of

lblControl1.Caption = OpenArgs

I have tried the information in the second suggestion, and the code does try
to work according the to the code. But, something strange is happening. I
have the first part of the code in the On Load event in the Main Menu form
(calling form), and the code for the end form control (Wayside Inspection
Form) in the On Load event. When I first try to open the Main Menu from the
previous form (Main Switchboard) I get an error message that says;

Runtime error: 94
Invalid use of Null

When I click the Debugger on the box, it opens up to this part of the code
in the end form (Wayside Inspection Form):

lblControl1.Caption = OpenArgs

When I close out of this, it goes to the end form. Then I use the navigation
Exits to go back to the Opening page, I get an error messages about the
graphics on that form not being OLE and other invalid info. When I get out
of all that, then go back through the navigation process, again it fires the
same error 94 at opening the Main Menu from the Main Switchboard, but, this
time when I close out of the debugger window, it opens the Main Menu again,
and if I go ahead and click on the command button to go to the next form all
works fine all the way to opening the last form, Wayside Inspection Form,
and the name Main Menu is displayed in lblControl1, as it should be.

I am really confused here. I have gone back over this several times, and
looked at it from various aspects, and I can't see where the problem is. Why
it errors first go round, then works the next?

Question, not sure is applies, but, just for clarification; I have a command
button on the Main Switchboard that opens the Main Menu, then a button on
the Main Menu that opens the next form in the process. The part of the code
for the Main Menu form (Calling form) says
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form". There are
actually 2 other forms to be opened after the Main Menu, the second of which
is a filter form that opens the last form. Just for curious, does the
'OpenForm' part of this code try to open the end form from the calling form?
As that is what is seems to be trying to do, thus by-passing the other two
forms.
Just trying to see what might be causing the strange action. The code does
work, but, something is detouring it on the way to the market. it seems.
Obviously, I'm made a mistake somewhere along the line.

I hope you will forgive my seeming rather dense here, but, this is my first
experience with this sort of thing, nor am I terribly knowledgeable with
using code yet.

Thank you so much for your time and help, I really appreciate it. It is very
close. ;-))

Jan :)

 
J

Jan Il

Hi Gerald,
The passing of information from Calling Form (or Calling
Menu) to Called Form is do-able through VBA. I can offer
two suggestions for you to practise with:

1. Accessing the controls once the form is loaded.
You can manipulate the controls on any 'loaded' form
through the Forms Collection.
e.g. In your Main form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form"
Forms![Wayside Inspection Form]!lblControl1.Caption = "Main
Form"

2. Passing the Form Name through as an opening argument
e.g In your Main Form, you can write something along the
following lines
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form"

and in your Form_Load() method of the Wayside Inspection
Form, write something along the lines of

lblControl1.Caption = OpenArgs

I have tried the information in the second suggestion, and the code does try
to work according the to the code. But, something strange is happening. I
have the first part of the code in the On Load event in the Main Menu form
(calling form), and the code for the end form control (Wayside Inspection
Form) in the On Load event. When I first try to open the Main Menu from the
previous form (Main Switchboard) I get an error message that says;

Runtime error: 94
Invalid use of Null

When I click the Debugger on the box, it opens up to this part of the code
in the end form (Wayside Inspection Form):

lblControl1.Caption = OpenArgs

When I close out of this, it goes to the end form. Then I use the navigation
Exits to go back to the Opening page, I get an error messages about the
graphics on that form not being OLE and other invalid info. When I get out
of all that, then go back through the navigation process, again it fires the
same error 94 at opening the Main Menu from the Main Switchboard, but, this
time when I close out of the debugger window, it opens the Main Menu again,
and if I go ahead and click on the command button to go to the next form all
works fine all the way to opening the last form, Wayside Inspection Form,
and the name Main Menu is displayed in lblControl1, as it should be.

I am really confused here. I have gone back over this several times, and
looked at it from various aspects, and I can't see where the problem is. Why
it errors first go round, then works the next?

Question, not sure is applies, but, just for clarification; I have a command
button on the Main Switchboard that opens the Main Menu, then a button on
the Main Menu that opens the next form in the process. The part of the code
for the Main Menu form (Calling form) says
DoCmd.OpenForm "Wayside Inspection Form",,,,,,"Main Form". There are
actually 2 other forms to be opened after the Main Menu, the second of which
is a filter form that opens the last form. Just for curious, does the
'OpenForm' part of this code try to open the end form from the calling form?
As that is what is seems to be trying to do, thus by-passing the other two
forms.
Just trying to see what might be causing the strange action. The code does
work, but, something is detouring it on the way to the market. it seems.
Obviously, I'm made a mistake somewhere along the line.

I hope you will forgive my seeming rather dense here, but, this is my first
experience with this sort of thing, nor am I terribly knowledgeable with
using code yet.

'k...I've been working a bit more with this, and I *think* I have an idea of
what is going on here.
When I first open the db, open the Main Switchboard, then click the button
to open the Main Menu, I get the error 94 message before the Main Menu is
opened. When I click debug it opens the code for the On Load event on the
target form. When I close out of there, it opens the target form, bypassing
the normal navigation process. When I step back along the forms using the
navigation lables on each one to the Main Switchboard, then click the button
to open the Main Menu again, I get no error message. The Main Menu opens,
but....at that same instant, for a flash of a millisecond, I see the Wayside
Inspection Form, the target form, open at the same time. I can then proceed
through the normal steps to open the target form, which will at times open
with the Main Menu name displayed in the lblControl1.

It would *seem*, as best I can tell, that, with the first attempt to open
the Main Menu, there is something going wrong, thus the error is fired. When
the debugging process has been gone through and I return to restart the
navigation process, it will sometimes then work as it should. But, it is
rather hit and miss. It may take several times going through the debug
process before it works correctly, however, eventually it does work. There
are no further errors, just the Main Menu name is not always displayed in
the respective control on the target form. That tells me some part of the
process is misfiring somewhere.

I'm not sure about my thinking on this, but, it would seem to be somewhere
with the DoCmd.OpenForm, especially, when for that flash of a second, the
target form is being opened prematurely when the calling form (Main Menu) is
being opened from the Main Switchboard. Perhaps the code in the calling
form needs to pass the Main Menu form name to the target form control when
it is opened, but, not attempt to open it from the Main Menu form. My
thinking on this may be way off the mark, and I am just not seeing how it is
supposed to be working. But, that is what caught my attention and raised
the question. Sorry this is so long, I'm trying to explain the events as
best I can.

Any suggestions as to where this problem may be occurring?

Thank you,

Jan :)
 
K

Ken Snell

Hi Jan -

This looks as if it's the next step in your database that we had been
discussing.

One idea: in the form with the footer labels, run code in the form's OnLoad
event that finds all the forms that are currently open (using the Forms
collection) and writes each form name into the labels' captions:

Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then _
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
Next frm
 
K

Ken Snell

Oops....one typo!

Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
End If
Next frm
 
J

Jan Il

Oops....one typo!
Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
End If
Next frm


.....shall I wait for the 3rd strike...... ;-))
 
J

Jan Il

Hi Ken!
Hi Jan -

This looks as if it's the next step in your database that we had been
discussing.

AHA! You peeked!! ;-))

But..yes. After our last discussion on the other side of the coin of this,
I did some testing and playing around with different ways to do this, and
how to best get the association between the two subjects tied together. It
suddenly occurred to me that perhaps I was trying to go about it the wrong
way. So, thought I'd try it from the other direction, where there were more
known factors to go by.

In view of your..ahmm...revised message below, I'll take the code there and
put it into the target form On Load event as you have instructed and see how
 
J

Jan Il

Hi Ken,
Oops....one typo!

Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
End If
Next frm

'k...now this works pretty good, and we're close here. But.....here's what's
hap'n now;

When I open the Main Menu from the Main Switchboard, I am not getting the
error 94 message at this point. However, I still see the 'phifftph' of the
target form being opened. Then...after I go through the rest of the
navigation process and finally open the target form, the name Main Menu is
in the 1st and 3rd controls, and the Main Switchboard name is in the second
control, and the 4th control is empty.

Now....in my original post for the other thread on the other side of the
subject, I mentioned a list of all the forms, tblFormNames, and it should be
in the cut down copy I sent you before. All the forms in the db are in that
table. I think the Opening Page may still be in the list in the copy you
have, I think I sent the copy before I deleted it from the list. It is the
only form that should be ignored by any of this. Until the database is
ready for closure, the primary form which all general user functions will
originate will be the Main Switchboard.

Here's a question; since only specific forms are to be considered in these
functions, can the On Load code in the target form yu just provided first
read the names of the forms in that table, then search for any of those
forms that are open, so that as they are opened they will be added to be
displayed in each of the controls according to the sequence they are opened
in the navigation process? Here's why; as it is now, it is taking ALL the
open forms and adding them to the controls. This being the case, the form
name in the first control should have been Main Switchboard, not the second.
The puzzling part is why Main Menu is also repeated in the 3rd control?
According to the navigation process, that should have been the Wayside
Switch Inspections Menu, and then the Wayside Switch Insp Filter in the last
one.

I may be wrong, but I *think* that the code in the On Load event of the Main
Menu is still prematurely opening the target form, thus, may be causing the
code not to function in the right sequence of the opening process. Using the
terms of our previous thread to stay on the same floor plan:

Main Switchboard (ctlFooter00) > Main Menu (ctlFooter01) > Wayside Switch
Inspections Form (ctlFooter02) > Wayside Switch Insp Filter (ctlFooter03)

As I mentioned in my other message here, I wonder about the OpenForm part of
the On Load code of the Main Menu, which is:

Private Sub Form_Load()

DoCmd.OpenForm "Wayside Switch Inspection Form"
Forms![Wayside Switch Inspection Form]!lblFooter00.Caption = "Main Menu"

End Sub

Should it actually be trying to 'open' that form from there? If my
understanding of this is incorrect please correct me. I'm still getting some
of my code terms crossed here and there...mostly
here.......but.....well.....yeah, there too. <sigh....>

Thank you for your time and assistance and bravery, I truly appreciate it.

Jan :)
 
K

Ken Snell

Can you send me the current version of this database? I think it'll be
easier for me to puzzle this out if I can see what it's doing for you.

--
Ken Snell
<MS ACCESS MVP>

Jan Il said:
Hi Ken,
Oops....one typo!

Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
End If
Next frm

'k...now this works pretty good, and we're close here. But.....here's what's
hap'n now;

When I open the Main Menu from the Main Switchboard, I am not getting the
error 94 message at this point. However, I still see the 'phifftph' of the
target form being opened. Then...after I go through the rest of the
navigation process and finally open the target form, the name Main Menu is
in the 1st and 3rd controls, and the Main Switchboard name is in the second
control, and the 4th control is empty.

Now....in my original post for the other thread on the other side of the
subject, I mentioned a list of all the forms, tblFormNames, and it should be
in the cut down copy I sent you before. All the forms in the db are in that
table. I think the Opening Page may still be in the list in the copy you
have, I think I sent the copy before I deleted it from the list. It is the
only form that should be ignored by any of this. Until the database is
ready for closure, the primary form which all general user functions will
originate will be the Main Switchboard.

Here's a question; since only specific forms are to be considered in these
functions, can the On Load code in the target form yu just provided first
read the names of the forms in that table, then search for any of those
forms that are open, so that as they are opened they will be added to be
displayed in each of the controls according to the sequence they are opened
in the navigation process? Here's why; as it is now, it is taking ALL the
open forms and adding them to the controls. This being the case, the form
name in the first control should have been Main Switchboard, not the second.
The puzzling part is why Main Menu is also repeated in the 3rd control?
According to the navigation process, that should have been the Wayside
Switch Inspections Menu, and then the Wayside Switch Insp Filter in the last
one.

I may be wrong, but I *think* that the code in the On Load event of the Main
Menu is still prematurely opening the target form, thus, may be causing the
code not to function in the right sequence of the opening process. Using the
terms of our previous thread to stay on the same floor plan:

Main Switchboard (ctlFooter00) > Main Menu (ctlFooter01) > Wayside Switch
Inspections Form (ctlFooter02) > Wayside Switch Insp Filter (ctlFooter03)

As I mentioned in my other message here, I wonder about the OpenForm part of
the On Load code of the Main Menu, which is:

Private Sub Form_Load()

DoCmd.OpenForm "Wayside Switch Inspection Form"
Forms![Wayside Switch Inspection Form]!lblFooter00.Caption = "Main Menu"

End Sub

Should it actually be trying to 'open' that form from there? If my
understanding of this is incorrect please correct me. I'm still getting some
of my code terms crossed here and there...mostly
here.......but.....well.....yeah, there too. <sigh....>

Thank you for your time and assistance and bravery, I truly appreciate it.

Jan :)

--
Ken Snell
<MS ACCESS MVP>

want
to;
names.
trying
form
control
on of
the Inspection
Menu
 
J

Jan Il

Can you send me the current version of this database? I think it'll be
easier for me to puzzle this out if I can see what it's doing for you.

On it's way now.

Thank you very much.

Jan :)
Jan Il said:
Hi Ken,


'k...now this works pretty good, and we're close here. But.....here's what's
hap'n now;

When I open the Main Menu from the Main Switchboard, I am not getting the
error 94 message at this point. However, I still see the 'phifftph' of the
target form being opened. Then...after I go through the rest of the
navigation process and finally open the target form, the name Main Menu is
in the 1st and 3rd controls, and the Main Switchboard name is in the second
control, and the 4th control is empty.

Now....in my original post for the other thread on the other side of the
subject, I mentioned a list of all the forms, tblFormNames, and it
should
be
in the cut down copy I sent you before. All the forms in the db are in that
table. I think the Opening Page may still be in the list in the copy you
have, I think I sent the copy before I deleted it from the list. It is the
only form that should be ignored by any of this. Until the database is
ready for closure, the primary form which all general user functions will
originate will be the Main Switchboard.

Here's a question; since only specific forms are to be considered in these
functions, can the On Load code in the target form yu just provided first
read the names of the forms in that table, then search for any of those
forms that are open, so that as they are opened they will be added to be
displayed in each of the controls according to the sequence they are opened
in the navigation process? Here's why; as it is now, it is taking ALL the
open forms and adding them to the controls. This being the case, the form
name in the first control should have been Main Switchboard, not the second.
The puzzling part is why Main Menu is also repeated in the 3rd control?
According to the navigation process, that should have been the Wayside
Switch Inspections Menu, and then the Wayside Switch Insp Filter in the last
one.

I may be wrong, but I *think* that the code in the On Load event of the Main
Menu is still prematurely opening the target form, thus, may be causing the
code not to function in the right sequence of the opening process. Using the
terms of our previous thread to stay on the same floor plan:

Main Switchboard (ctlFooter00) > Main Menu (ctlFooter01) > Wayside Switch
Inspections Form (ctlFooter02) > Wayside Switch Insp Filter (ctlFooter03)

As I mentioned in my other message here, I wonder about the OpenForm
part
of
the On Load code of the Main Menu, which is:

Private Sub Form_Load()

DoCmd.OpenForm "Wayside Switch Inspection Form"
Forms![Wayside Switch Inspection Form]!lblFooter00.Caption = "Main Menu"

End Sub

Should it actually be trying to 'open' that form from there? If my
understanding of this is incorrect please correct me. I'm still getting some
of my code terms crossed here and there...mostly
here.......but.....well.....yeah, there too. <sigh....>

Thank you for your time and assistance and bravery, I truly appreciate it.

Jan :)

--
Ken Snell
<MS ACCESS MVP>

Hi Jan -

This looks as if it's the next step in your database that we had been
discussing.

One idea: in the form with the footer labels, run code in the form's
OnLoad
event that finds all the forms that are currently open (using the Forms
collection) and writes each form name into the labels' captions:

Dim frm As Form
Dim intForm As Integer
intForm = 0
For Each frm in Forms
If frm.Name <> Me.Name Then _
Me.Controls("lblFooter" & _
Format(intForm,"00")).Caption = _
frm.Name
intForm = intForm + 1
Next frm


--
Ken Snell
<MS ACCESS MVP>

Hi all -

I have two questions. I have a series of functions where I simply want
to;

1. Contact/call a specific control on a specific form.
1. From a specific form when it is opened.
3. Display the name of the contacting/calling form in the specific
control
Caption when the specific form it is on is opened.

All controls on all the end/target forms have the same generic
names.
I
have
been playing with this for some time, and trying to figure out how to
get
each control to call the name of the related form into it when the
end/target form is opened, when there are various forms involved
in
the
process of reaching the end/target form and will vary from
function
to trying from
the Here's
why;
series
of form control displayed
in
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top