Can I enter instruction via code ? (1 Viewer)

kirkm

Registered User.
Local time
Today, 16:27
Joined
Oct 30, 2008
Messages
1,257
My subform has 50 text boxes I want to add "=myfunction" into each After update event. Do I have to do this one by one in direct mode, or can I use code ?
If yes, can I see an example how? Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:27
Joined
Feb 19, 2002
Messages
43,266
I guess I don't understand the purpose of this. What is the function doing and how would it know what control to operate on if you placed the same function in each AfterUpdate event? Perhaps, using a loop in the FORM's BeforeUpdate event would be simpler.

Further, this has the appearance of being a spreadsheet rather than a normalized table. Can you tell us more about the form and the underlying table.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:27
Joined
Feb 19, 2013
Messages
16,610
first - it needs to be "=myFunction()"

second, in form design view why not just select all the required controls and type it in just the once
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:27
Joined
Jul 9, 2003
Messages
16,280
My subform has 50 text boxes I want to add "=myfunction" into each After update event. Do I have to do this one by one in direct mode, or can I use code ?
If yes, can I see an example how? Thanks.

Yes you can...

ChrisO did an excellent article on this a few years back - Soft-coded event handlers.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:27
Joined
Jul 9, 2003
Messages
16,280
Also I got this idea that you can't use a subroutine, it has to be a function. I switched my PC off, so I can't check, just now...
 
Last edited:

kirkm

Registered User.
Local time
Today, 16:27
Joined
Oct 30, 2008
Messages
1,257
Interesting... Pat, how would the Forms Before Update event know which control to process?
CJ, I can't do that because each event needs to pass it's Controls Name (or a number) to the function.

And UG, thanks, that was a good link. Chris is doing what I want, but at run time. Ideally I'm after some way to save me repeated typing in design mode. Why I'm not sure... more suited to my low level of expertise perhaps! Opening properties and see/get to the event code in familiar manner. Although maybe Chris way is perfectly ok...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:27
Joined
Jul 9, 2003
Messages
16,280
Chris is doing what I want, but at run time.

You are far better off with Chris's way because you can change things quickly and easily! If you hard code it, and something is wrong, then you have to manually change it all again...
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:27
Joined
Feb 19, 2013
Messages
16,610
I can't do that because each event needs to pass it's Controls Name
I don't know what your function is supposed to do, but you might find it worthwhile investigating screen.activecontrol and screen.previouscontrol

screen.activecontrol.name will return the name of the control
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:27
Joined
Feb 19, 2013
Messages
16,610
but if you want a bit of code to assign a function a simply loop will do it


dim ctrl as control
for each ctrl in me.controls
ctrl.afterupdate="=myfunction(" & ctrl.name & ")"
next ctrl

will need additional code to exclude controls which don't have the afterupdate event such as labels and other factors such as spaces in names.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:27
Joined
Feb 19, 2002
Messages
43,266
How many threads do you have going on this topic? Please DO NOT start multiple threads on the same topic.
 

Users who are viewing this thread

Top Bottom