Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / November 2005

Tip: Looking for answers? Try searching our database.

Setting code on Command Button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DS - 15 Nov 2005 18:09 GMT
I have a command button where I want to leave the OnClick Event Blank.
I want to set it from the previous form.  If I open it from form1 the
the OnClick event is This.......
If I open it from form2 then the OnClck event is that.  How would I do this?
Thanks
DS
Rick Brandt - 15 Nov 2005 18:22 GMT
> I have a command button where I want to leave the OnClick Event Blank.
> I want to set it from the previous form.  If I open it from form1 the
> the OnClick event is This.......
> If I open it from form2 then the OnClck event is that.  How would I
> do this? Thanks
> DS

No need to leave the OnClick blank.  Just put your various code routines in
their own functions or sub-routines and then have your Click event decide
which one of those to call.  Assuming you use the OpenArgs property to
determine the calling form...

Select Case Me.OpenArgs
   Case "Form1"
       Call SomeSub
   Case "Form2"
       Call SomeOtherSub
End Select

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

DS - 15 Nov 2005 18:25 GMT
>>I have a command button where I want to leave the OnClick Event Blank.
>>I want to set it from the previous form.  If I open it from form1 the
[quoted text clipped - 14 lines]
>         Call SomeOtherSub
> End Select

Looks good Rick, but how do you use the OpenArgs tocall the form?
Thanks
DS
Rick Brandt - 15 Nov 2005 19:03 GMT
>> No need to leave the OnClick blank.  Just put your various code
>> routines in their own functions or sub-routines and then have your
[quoted text clipped - 9 lines]
>>
> Looks good Rick, but how do you use the OpenArgs tocall the form?

OpenArgs has a dual personality.  It is an optional argument that can be
used in the OpenForm method.

DoCmd.OpenForm "FormName",,,,,,"Some String Value"

It is also a property of a form that can be referenced by any code in that
form.  It's just that the OpenArgs property will be Null (or a zero length
string perhaps) if the form is not opened with OpenForm having the OpenArgs
argument supplied.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

DS - 15 Nov 2005 21:38 GMT
>>>No need to leave the OnClick blank.  Just put your various code
>>>routines in their own functions or sub-routines and then have your
[quoted text clipped - 19 lines]
> string perhaps) if the form is not opened with OpenForm having the OpenArgs
> argument supplied.

Thanks Rick, On target as always!!
DS
Albert D.Kallal - 16 Nov 2005 01:31 GMT
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.....

Signature

Albert D. Kallal   (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
http://www.members.shaw.ca/AlbertKallal

DS - 16 Nov 2005 15:08 GMT
> You have two choices:
>
[quoted text clipped - 41 lines]
>
> However, the above should work for you.....

Great thanks Albert the second one works even better than the first one
for me.
Thanks
DS
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.