VBA cmd for button click in a access form

What is the  vba function/procedure in Access that will pass through a button click on a form?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Not quite sure what you mean?

In an access form, if you place a button on the form, an then display the properties dialog, you can click on the Events tab and then expand the drop-down associated with the Click event and select the [Event Procedure] option.

Then click on the elipse (...) to the right of the drop-down to have Access open the VBE interface to the code segment for that event, which will look something like:

Private sub yourCommandButtonName_Click()

End Sub

Then you insert code in side that procedure to accomplish whatever you want to do.  Alternatively, if you have the control wizard enabled, it will walk you through some options applicable to the command button and write macro code for you.
Wayne Taylor (webtubbs)Commented:
To simulate the clicking of a CommandButton, simply call it's Click event handing routine....

    Call CommandButton1_Click()

...where CommandButton1 is the name of the control.
tike55Author Commented:
The example above did not work.  Below is code I am using for my form.  I want to add the click button in the else statement.  

Function Message()
Dim MSGBOXRSP As Integer

MSGBOXRSP = MsgBox("                    Not Found.  Add new item?", vbOKCancel)

If LResponse = vbOK Then
  ' {me.SearchField=null}
   [Forms]!Item_Master.SearchField = Null

End If
End Function
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dale FyeOwner, Developing Solutions LLCCommented:
I'm not sure what you are trying to accomplish on the line you have remarked out. But your first problem is that you never declare or set a value for LResponse, so I would start with:

Function Message()

    Dim MSGBOXRSP As Integer

    MSGBOXRSP = MsgBox("Not Found.  Add new item?", vbOKCancel)

    If MSGBOXRSP = vbOK Then
      ' {me.SearchField=null}
         [Forms]!Item_Master.SearchField = Null
    End If
End Function
Are you asking how to run code that is in a click event without actually clicking the control?

Call yourCommandButtonName_Click()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Helen FeddemaCommented:
Can you describe more precisely what you are trying to do here?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.