Opening Forms without DoCmd.OpenForm

G

GrahamT

I am wanting to create code to open any form, but without using th
DoCmd.OpenForm construct. The code I am playing with looks lik
this

Dim frm As For
Set frm = New [Form_MyForm
frm.Visible = Tru

Where the name of the form is 'MyForm
(The key word 'New' may or may not be present

However, I want to pass the name of the form via a variable yet th
code above has the name hard-coded

As I said, I do NOT want to use the DoCmd.OpenForm construc

Does anyone out there know of a way to pass the name of the form via
variable

I would be much obliged

Graham
 
P

Paul Overway

For what you want to do, you MUST use Docmd.OpenForm. This is probably less
of a problem than you think though...

Dim frm As Form

Docmd.OpenForm "SomeForm",,,,,acHidden
Set frm = Forms("SomeForm")
frm.Visible
'etc

Are you trying to open multiple instances of the form or something. If yes,
there is a bit more involved.
 
G

GrahamT

Hi Paul. Thanks for your time

Yes, I'm writing a replacement for the rather limited 'DoCmd.OpenForm
construct to include multiple instance control and a few othe
refinements. Yes there is quite a lot involved, but much i
reasonably straightforward

I could use the 'DoCmd.OpenForm' construct for opening the defaul
instance, but since the DoCmd object is built within Access from mor
basic (with or without a capital B) commands, it would seem bette
practice (& better program flow) to also use those

As is often the case with Access (& Basic etc.), correct synta
can be elusive & without getting it exactly correct you can u
the proverbial gum-tree. Hence my original posting

What d'you think

Cheers
Graha
 
G

GrahamT

GrahamTwrote
I am wanting to create code to open any form, but without using th
DoCmd.OpenForm construct. The code I am playing with looks lik
this
Dim frm As For
Set frm = New [Form_MyForm
frm.Visible = Tru

Where the name of the form is 'MyForm
(The key word 'New' may or may not be present

However, I want to pass the name of the form via a variable yet th
code above has the name hard-coded
As I said, I do NOT want to use the DoCmd.OpenForm construc

Does anyone out there know of a way to pass the name of the form vi a variable

I would be much obliged

Graham

Thought I'd update this post with some additional info. that ma
prompt further thoughts

Talking with a pal of mine, who is quite familiar with Visual Basic 6
He says that the way I'm also doing it at the moment is the same a
his way round the very same problem: that is, to create a look-u
table of forms. For example

Function Instance(strForm As String, fNew As Boolean) As For
If fNew The
Select Case strFor
Case "Customers
Set Instance = New [Form_Customers
Case "Districts
Set Instance = New [Form_Districts
Case "Invoices
Set Instance = New [Form_Invoices
End Selec
Els
Select Case strFor
Case "Customers
Set Instance = [Form_Customers
Case "Districts
Set Instance = [Form_Districts
Case "Invoices
Set Instance = [Form_Invoices
End Selec
End I
End Functio

So, then, the problem isn't new and isn't just me who has it

Another thing I've noticed is this

Access' Help claims that creating the default instance in this wa
(e.g. Set Instance = [Form_Customers]) is the equivalent to openin
the form from the Database window
However, If you (or should it be I) do this & then open the for
from the Database window, another instance - presumably the correc
default instance - is opened. This shows that using 'Set Instance
[Form_Customers]' does NOT truely open the default instance (als
suggested by the fact that the form can not be switched into Desig
View by the menu button)

Are there any experts out there who can help or comment on thes
findings
 

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