Forms Syntax

P

Peter Hallett

I would appreciate some assistance with a bit of syntax.

The statements:
Dim MyForm As Form

Set MyForm = Forms![frm_Some_Form]

seem to work OK with frm_Some_Form as a literal but I can’t seem to find an
equivalent statement with the form name as a variable. In the case of
passing the name as an argument to a procedure, for example, the code might
look like:-

Public Sub DoSomething (InFormName As String)
Dim MyForm As Form

Set MyForm = Forms! ??????
…
…
End Sub

but I am unable to find a suitable Set statement which will satisfy the
compiler.
 
D

Douglas J. Steele

Public Sub DoSomething (InFormName As String)
Dim MyForm As Form

Set MyForm = Forms(InFormName)

…

End Sub

The form, of course, must be already be open for this to work.
 
P

Peter Hallett

Thank you, Doug. I had to use a similar syntax some time ago, and I knew it
was straightforward but, for the life of me, I could not reproduce it. You
have saved me further fruitless hours ploughing through more 'coffee-table'
manuals to very little effect. I am grateful.

Douglas J. Steele said:
Public Sub DoSomething (InFormName As String)
Dim MyForm As Form

Set MyForm = Forms(InFormName)

…

End Sub

The form, of course, must be already be open for this to work.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Peter Hallett said:
I would appreciate some assistance with a bit of syntax.

The statements:
Dim MyForm As Form

Set MyForm = Forms![frm_Some_Form]

seem to work OK with frm_Some_Form as a literal but I can’t seem to find
an
equivalent statement with the form name as a variable. In the case of
passing the name as an argument to a procedure, for example, the code
might
look like:-

Public Sub DoSomething (InFormName As String)
Dim MyForm As Form

Set MyForm = Forms! ??????
…
…
End Sub

but I am unable to find a suitable Set statement which will satisfy the
compiler.
 

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