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 / January 2008

Tip: Looking for answers? Try searching our database.

Run Code in Group

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
F1stman - 08 Jan 2008 20:13 GMT
Hello All,

I am not new to Access but have not used modules, etc. very much. On a form
I have a script about 80 lines long that I want to run on the lost focus
event of 20 different text boxes. It checks all values against new
calculations. The code has been tested and runs fine.

The Goal: How can I save that code and then simply enter one line of code
for each lost focus event? Is there a way to save it as a script?

Please let me know if I have not been clear. Thank you in advance for the
help.

Adam Kemp
Klatuu - 08 Jan 2008 20:34 GMT
Put the code in a standard module.  Make sure it is identified as a Public
Function or Sub.

Call the code from the event. Are you sure you want to use Lost Focus?
Describe what you are doing, please.
Signature

Dave Hargis, Microsoft Access MVP

> Hello All,
>
[quoted text clipped - 10 lines]
>
> Adam Kemp
F1stman - 08 Jan 2008 20:58 GMT
Thanks Dave,

I have a form which lists cost information for a construction project. Each
value is calculated as a percentage of other values. There is also a manual
override for each field. The manual and calculated are unbound. The script
calculated and checks to see if each cost has a manual entry. If not it
enters the calculated amount into the bound text box. If it does have a
manual it enters that. It has to be on each since changing the value for one
will change it for the others. I also would like to run the script when the
form is opened.

Thanks again, Adam

> Put the code in a standard module.  Make sure it is identified as a Public
> Function or Sub.
[quoted text clipped - 16 lines]
> >
> > Adam Kemp
Klatuu - 08 Jan 2008 21:03 GMT
Use the Form's Load event to run it the first time.

Instead of the Lost Focus event, use the After Update event.  If you use the
Lost Focus event, you will be running the code when maybe it isn't necessary.
The Lost Focus event fires every time you leave the control.  The After
Update event only fires if data in the control has been changed.  Using the
Lost Focus event means that you will run the code even if no changes have
been made.
Signature

Dave Hargis, Microsoft Access MVP

> Thanks Dave,
>
[quoted text clipped - 29 lines]
> > >
> > > Adam Kemp
F1stman - 09 Jan 2008 18:50 GMT
Dave,

I feel foolish having to ask this but how do I run the module from the event?

Adam

> Use the Form's Load event to run it the first time.
>
[quoted text clipped - 38 lines]
> > > >
> > > > Adam Kemp
Klatuu - 09 Jan 2008 18:56 GMT
Well, you don't run a module.  A module is a contain for Functions and Subs,
so you will be running one of those.

To put code in an event, open the form in design view.  Select the control
you want the procedure to run from and open the properties dialog.  Select
the Events tab.  Select the event you want to use.  In this case, the after
update event.  Click on the small command button to the right with the 3
dots.  When the dialog opens, select Event Procedure.  The VB editor will
then open with the cursor positioned in the event sub.  Enter the code there.
Signature

Dave Hargis, Microsoft Access MVP

> Dave,
>
[quoted text clipped - 44 lines]
> > > > >
> > > > > Adam Kemp
 
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.