If statement based on button click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a form (e.g. formA) which has two buttons - ViewPO and EditPO.

Now Clicking of ViewPO opens up another form (e.g. formB). Similarly,
clicking on EditPO opens up the same formB
Now on formB I have to write a if statement
This if statement is based on the previous button click.

In other words:
If button ViewPO has been clicked then
Do This
If button ViewEditPO has been clicked then
Do That
Else
...
End if

Is there any way to put this concept in code. I am specially looking for if
a button click event can be the basis of a if statement. Thanks in advance.
 
I'm assuming you're using the OpenForm method to open formB. The OpenForm
method allows you to pass a free-form value as the OpenArgs parameter. You
can then check the value of OpenArgs in formB to decide what to do.

Change how you open formB to

DoCmd.OpenForm "formB", OpenArgs:="ViewPO"

or

DoCmd.OpenForm "formB", OpenArgs:="EditPO"

as appropriate.

In the Load event of formB, put code like:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Select Case Me.OpenArgs
Case "EditPO"
' do what you want because EditPO was clicked on the previous form
Case "ViewPO"
' do what you want because ViewPO was clicked on the previous form
End Select
End If

End Sub
 
Back
Top