You have two choices:
You could pickup the name of the "previous" form in the 2nd forms on-load
even.
strPrevoius = screen.ActiveForm.Name
note that you can pick the name of the previous form as above as long as you
have NOT yet exited the on-open, and even the on-load event of the form. The
instant the on-load routine is finished then above would course refer to the
current form.
"strPrevous" would course have to be a module level variable defined at the
start of the forms module code.
Then, in your button click code, you can go
if strPrevous = "form1" then
bla bal bal
end if
if strPrevous = "form2" then
bla bal alb
end if
Another approach is to simply "leave" the on-click event of the control
blank, and set what function you want the on-click event to turn. You would
do this in the "calling" code..
eg:
docmd.OpenForm "form B"
forms("formB").Contorls("myButtion").OnClick = "=MyCode1()"
This means you can at runtime "modify" what public function the button will
run.....
"mycode" can either be a public function in the forms module, or in a
standard code module...
Last, but not least, since I written a zillion applications, and never had
to do the above, my spider sense tells me there is another way to do this by
changing your design........
However, the above should work for you.....