By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,244 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,244 IT Pros & Developers. It's quick & easy.

Running Button Method from Another Form

P: n/a
I am trying to design a button in one form that opens
another form and executed a button method within that form.

I want to button to open a form based on a different table,
then execute the code connected with a cmdNew_Record button
in the second form. This command shows several hidden
buttons and instructions, as well as opening a blank record.

I have tried a line "RunCommand acRunCmd..." to try to get
the second method to run, but I keep getting argument errors.

I tried changing the "Private Sub" to "Public Sub" on the
header for the method I want to run, but that did not do
any good.

Thanks for your assistance in advance.

ps: In case it's not obvious, I'm a neophyte, a high school
teacher trying to keep my mind alive.

--jade
ja**@pacific.net

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Jade Tippett" <ja**@pacific.net> wrote in message
news:40**************@pacific.net...
I am trying to design a button in one form that opens
another form and executed a button method within that form.

I want to button to open a form based on a different table,
then execute the code connected with a cmdNew_Record button
in the second form. This command shows several hidden
buttons and instructions, as well as opening a blank record.

I have tried a line "RunCommand acRunCmd..." to try to get
the second method to run, but I keep getting argument errors.

I tried changing the "Private Sub" to "Public Sub" on the
header for the method I want to run, but that did not do
any good.

Thanks for your assistance in advance.

ps: In case it's not obvious, I'm a neophyte, a high school
teacher trying to keep my mind alive.

--jade
ja**@pacific.net

I can think of a number of ways to approach this, but one possible avenue to
explore is to look at the OpenArgs parameter you can pass when you use the
DoCmd.OpenForm. For example,

DoCmd.OpenForm "frmTwo", , , , , , "MyKeyWord"

will open a form named "frmTwo" passing a string "MyKeyWord"

This can be picked up in frmTwo's Open event
Private Sub Form_Open(Cancel As Integer)

If Me.OpenArgs = "MyKeyWord" Then
Me.cmdSpecial.Visible = True
Me.txtSpecial.Visible = True
DoCmd.GoToRecord , , acNewRec
End If

End Sub
In other words, if you open frmTwo normally, nothing happens. But if you
pass it "MyKeyWord" as a OpenArgs parameter, it knows it needs to open in a
'special way' and run that code.

Does that make sense?
Fletcher
Nov 12 '05 #2

P: n/a
Jade Tippett <ja**@pacific.net> wrote in news:403157B1.3040104
@pacific.net:
I am trying to design a button in one form that opens
another form and executed a button method within that form.

I want to button to open a form based on a different table,
then execute the code connected with a cmdNew_Record button
in the second form. This command shows several hidden
buttons and instructions, as well as opening a blank record.

I have tried a line "RunCommand acRunCmd..." to try to get
the second method to run, but I keep getting argument errors.

I tried changing the "Private Sub" to "Public Sub" on the
header for the method I want to run, but that did not do
any good.

Thanks for your assistance in advance.

ps: In case it's not obvious, I'm a neophyte, a high school
teacher trying to keep my mind alive.

--jade
ja**@pacific.net


To open the second form, use the docmd.openform "form2"

Then, you need to trigger the On Click event procedure belonging
to the cmdNew_Record button on this form that does the actions
you have programmed.

In order to do this, the sub procedure must be public.
All you need is to add the following line in your first form's
button, after you open the form. You might need to insert a delay
to allow the form to open, so

dim x as single
x = timer
do while timer < x + 1 ' gives 1 second delay.
DoEvents
Loop
CALL forms!form2!cmdNew_Record_Click

Bob Q

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.