docmd.openform

G

Guest

Hi All,
Within my db (access2003) I do use several times a button to open a form.
Lets say that on 1 form I have 4 buttons (banktypes, relationtypes and so on).
Now I do use within the procedure the command docmd.openform.
As i have declared the string stDocName I am able to reduce the procedure like
sub button1_clik()
stDocname = "form1"
call OpenRequestedForm
end sub
sub OpenRequestedForm()
docmd.openform stDocName
end sub
When I place the sub OpenRequestedForm within the same procedure everything
works fine. However placing it within a other procedure so other forms can
also make use of it does not work.
Within the other procedure I have tried to put in / leave out the
declaration of stDocName.
the debugger keeps telling me that it can not find a value for stDocname.

Any help would be very fine.
Greetings Harry
 
G

Guest

Use a function within a module that you can pass to it the form name, and
open the form from it

Function OpenRequestedForm(stDocName As String)
' Function that recieve the form name and open it
Docmd.OpenForm stDocName
end sub

In the OnClick event use it as
sub button1_clik()
stDocname = "form1"
OpenRequestedForm stDocname
end sub

You can use this function any where in the database, aslong that it will be
written within a module, and not within the form
 
G

Guest

How someone can overlook a solution when he is to much focused to solve a
problem.
Thanks a lot for your fast reply, it of course did work out as it should.

Greetings Harry
 

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