Macro to close all open forms

K

Ken Snell

This error suggests that you don't have a valid form name in the clicked
label's caption. I just tested the subroutine's code here and it worked as
advertised.

Insert this step just above the line that is erroring and let's see what the
caption of the label actually is:

Debug.Print ctl.Caption
 
J

Jan Il

Hi Ken,
This error suggests that you don't have a valid form name in the clicked
label's caption. I just tested the subroutine's code here and it worked as
advertised.

Insert this step just above the line that is erroring and let's see what the
caption of the label actually is:

Debug.Print ctl.Caption

I placed the above step just above the line that is erroring as you
instructed.

Else
Debug.Print ctl.Caption
< DoCmd.OpenForm ctl.Caption >
End If
End If
End If
Next ctl
End Sub

I am now getting an error message that says:
Run-time error 2494
Action or method requires a Form Name argument

The same line is being highlighted with this error. (< > above)


Here is the code in the On Click Event for the label:

Private Sub lblFooter00_Click()

Call CloseOpenAssociatedForms(Me, Me.lblFooter00.Name)

End Sub


Thank you very much for your time and patience. I truly do appreciate it.

Jan :)
 
K

Ken Snell

Did anything print in the Immediate Window from the Debug.Print statement?
You didn't say.

Well, let's do some long-range debugging then.

Put a breakpoint on this line:

If ctl.Name <> strLabelName Then

When the code breaks, put your cursor over the ctl.Caption part of the
offending line (the line where the code gives the error when running) and
see what shows in the popup window. Or, in the Immediate Window, type this:

?ctl.Caption

And see what it says. Post that for us to continue the debugging.
 
J

Jan Il

Hi Ken!
Did anything print in the Immediate Window from the Debug.Print statement?
You didn't say.

Sorry..no, nothing showed up in the immediate window.
Well, let's do some long-range debugging then.

Put a breakpoint on this line:

If ctl.Name <> strLabelName Then

When the code breaks, put your cursor over the ctl.Caption part of the
offending line (the line where the code gives the error when running) and
see what shows in the popup window. Or, in the Immediate Window, type this:

?ctl.Caption

And see what it says. Post that for us to continue the debugging.

(From the immediate window)

Run-time error '424'
Object required

Jan :)
 
K

Ken Snell

OK - this helps identify why it's not working.....for some reason, the ctl
object variable isn't being recognized in that line as a control object.
I've looked again at the code that you posted from your module's subroutine,
and it looks fine. And I used that code directly from your post to test.

OK - Can you zip up the database and email to me (remove this is not real
from my address) and I'll take a look .... something strange is happening
here.
 
J

Jan Il

Hi Ken!
OK - this helps identify why it's not working.....for some reason, the ctl
object variable isn't being recognized in that line as a control object.
I've looked again at the code that you posted from your module's subroutine,
and it looks fine. And I used that code directly from your post to test.

OK - Can you zip up the database and email to me (remove this is not real
from my address) and I'll take a look .... something strange is happening
here.

Obviously there is something that you don't have in your test set up that I
do on this end and it's choking the code. I've researched and checked
everything I can think of, but, nothing is standing out that I can see.

Thank you very much.

Jan :)
 
J

Jan Il

OK - this helps identify why it's not working.....for some reason, the ctl
object variable isn't being recognized in that line as a control object.
I've looked again at the code that you posted from your module's subroutine,
and it looks fine. And I used that code directly from your post to test.

OK - Can you zip up the database and email to me (remove this is not real
from my address) and I'll take a look .... something strange is happening
here.

It's on the way now...if you do not get it let me know and I'll try again.
;-)

Jan :)
 
K

Ken Snell

I've reviewed the database. I cannot find any code or macro that is actually
setting the caption of the footer labels to the names of the forms. Thus,
the caption of each label is an empty string, and when the code runs, the
caption contains no form name. That is why the code is failing.

You need to add code / macro to the database that will write the names of
the open forms into those captions. Then it should work for you.
 
J

Jan Il

Hi Ken!
I've reviewed the database. I cannot find any code or macro that is actually
setting the caption of the footer labels to the names of the forms. Thus,
the caption of each label is an empty string, and when the code runs, the
caption contains no form name. That is why the code is failing.

You need to add code / macro to the database that will write the names of
the open forms into those captions. Then it should work for you.

Ah.....will do. :)

Thank you so very much for all your time and help. I truly do appreciate it.

Very best regards,
Jan :)
 

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