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?
tike55Asked:
Who is Participating?
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 FyeCommented:
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.
0
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.
0
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}
Else
   [Forms]!Item_Master.SearchField = Null


End If
End Function
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dale FyeCommented:
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}
    Else
         [Forms]!Item_Master.SearchField = Null
    End If
End Function
0
PatHartmanCommented:
Are you asking how to run code that is in a click event without actually clicking the control?

Call yourCommandButtonName_Click()
0

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?
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.