forms() err - Can't find the form "frmDspEvents"

D

Dennis

Hi,

OS - XP Pro SP3
Access - XP Office Pro - SP3


My main forms opens up a form call frmDspEvents where I display the events
as they fire. (I'm learning about access).

I can see the form on my screen, but when I execute the statememt
Forms("frmDspEvents") I receive the error message "Can't find the Form
"frmDspEvents" referenced in a macro expression of Visual Basic code.

I've read the other entries with respect to this error and I understood
them, they said it will work if the form is open. My form is opened and it
fails. frmDspEvents is a pop-up form that I open from my initial form using
the code:


Set frmDspEvent = New Form_frmDspEvents ' Open dsp event
frmDspEvent.SetFocus
Call Display_Event("Form_Open") ' Display event


Private Sub Display_Event(strEventName as String)
if IsFormLoaded("frmDspEvent") then frmDspEvent.ShowEvent strEventName
End sub

It is end the IsFormLoaded where the error is occuring when I run the line:

if forms(strFormName).CurrentView <> 0 then

I also noticed that I never dimed the variable frmDspEvent and VB never
complained even though I have Option Explicit at the top of the module.

Thanks for you assitance.
 
M

Maurice

Hi Dennis,

I tried this:

sub test
Dim strFormName As String
strFormName = "Customer list"
DoCmd.OpenForm strFormName
If Forms(strFormName).CurrentView <> 0 Then
MsgBox strFormName
End If
end sub

This opened the form Customer List and after that I got the messagebox
stating Customer List. So it seems the code should work but then again I did
dim the variable first. Also make sure that if you variable is a string it
has double qoutes around it's name.

hth
 
D

Dirk Goldgar

Dennis said:
Hi,

OS - XP Pro SP3
Access - XP Office Pro - SP3


My main forms opens up a form call frmDspEvents where I display the events
as they fire. (I'm learning about access).

I can see the form on my screen, but when I execute the statememt
Forms("frmDspEvents") I receive the error message "Can't find the Form
"frmDspEvents" referenced in a macro expression of Visual Basic code.

I've read the other entries with respect to this error and I understood
them, they said it will work if the form is open. My form is opened and
it
fails. frmDspEvents is a pop-up form that I open from my initial form
using
the code:


Set frmDspEvent = New Form_frmDspEvents ' Open dsp event

This method of instantiating the form's class object isn't quite the same as
opening the form, so far as Access is concerned. In particular, it creates
a non-default instance of the form that cannot be indexed by name in the
Forms collection. The form is added to the Forms collection, but can't be
found by Forms!frmDspEvents or Forms("frmDspEvents").

This is, simply speaking, a bad way to "open" forms, unless your intent is
to open multiple instances of the same form (in which case it's an
invaluable technique). Instead, do this:

DoCmd.OpenForm "frmDspEvents"

and if you need an object reference to the form, then after the above line,
write:

Set frmDspEvent = Forms!frmDspEvents

But it isn't clear to me, in this particular case, that you need such an
object reference. If you open the form using DoCmd.OpenForm, you won't
normally have to do anything to set the focus to the form, as Access will do
that.
I also noticed that I never dimed the variable frmDspEvent and VB never
complained even though I have Option Explicit at the top of the module.

That's odd, and I can't explain it with the information available.
 
M

Marshall Barton

Dennis said:
OS - XP Pro SP3
Access - XP Office Pro - SP3


My main forms opens up a form call frmDspEvents where I display the events
as they fire. (I'm learning about access).

I can see the form on my screen, but when I execute the statememt
Forms("frmDspEvents") I receive the error message "Can't find the Form
"frmDspEvents" referenced in a macro expression of Visual Basic code.

I've read the other entries with respect to this error and I understood
them, they said it will work if the form is open. My form is opened and it
fails. frmDspEvents is a pop-up form that I open from my initial form using
the code:


Set frmDspEvent = New Form_frmDspEvents ' Open dsp event
frmDspEvent.SetFocus
Call Display_Event("Form_Open") ' Display event


Private Sub Display_Event(strEventName as String)
if IsFormLoaded("frmDspEvent") then frmDspEvent.ShowEvent strEventName
End sub

It is end the IsFormLoaded where the error is occuring when I run the line:

if forms(strFormName).CurrentView <> 0 then

I also noticed that I never dimed the variable frmDspEvent and VB never
complained even though I have Option Explicit at the top of the module.


I have no idea why Option Explicit didn't complain about the
undeclared object variable. Did you use Debug - Compile?
The way you are using the object variable in multiple
procedure implies that it is a module level variable. Check
tge top of the module. I suggest that you seriously
consider passing the object variable in the functions'
argument list

Only forms opened using DoCmd.OpenForm are in the Forms
collection under their own name. So, your IsLoaded function
will have to deal with that. Possibly by error trapping an
attempt to refer to a property through the form object?

That is because Set x=New Form_y can be used to open many
instances of form y, so the Forms collection index must be
artifically created. And to anticipate your next question,
there is no reasonable way to determine the index that
Access generated.
 
D

Dennis

All,

Thanks for your assitance. I've been out sick and I'm just now feeling
better.

Anyhow, I fould my variable declaration. I changed it to a global, but did
not indicate it in the variable name. I am moving it to the top of the form
in the variable declaration section and removing it from global.

I will make the changes suggested and let you know.

Thanks
 

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