calling a sub in an event

N

NasaDBGuy

Running Access 2003

I'm trying to loop through all the text boxes of my form to assign my user
defined sub when the dirty event occurs. Here' what I have so far:

public sub textValue(ctrl as control)
dim message as string
message = ctrl.value
msgbox = message
end sub

public sub textLoop()
dim ctlLoop as control

For each ctlLoop in Forms!spacecraft.form.controls
if typeof ctlLoop is textbox then
ctlLoop.OnDirty = "[textValue(ctlLoop)]" 'this line of code does not work
'when I fire the dirty event for that control Access tells me it is looking
for a 'macro that does not exist.
end if
next ctlLoop
end sub


the textLoop() and textValue() subs are written in a module. I call the
textLoop sub when the form loads. spacecraft is the name of my form.

This is similar to code I got from access help on the OnUndo property:

Dim ctlLoop As Control

For Each ctlLoop In Forms(0).Controls
If ctlLoop.Type = acTextBox Then
ctlLoop.OnUndo = "[Event Procedure]"
End If
Next ctlLoop

Any help would be appreciated.
 
G

George Nicholson

The following has worked for me for years when creating a form from scratch
(in Design view):
frm.BeforeUpdate = "=BlanketBeforeUpdate([ctlAddedBy])"
(Note: BlanketBeforeUpdate expects a Control for its argument, just like
your textValue procedure does.)

Therefore, I would try:
ctlLoop.OnDirty = "=textValue([" & ctlLoop.Name & "])"

I've never used a procedure, only Functions (that return a value) for this.
Not sure if there's a reason for that, but there might be. :) So, if you
run into problems, try changing textValue() into a function, even if all it
does is return True.

Not sure why you would want to do this every time the form loads however.
Why not just do it once and save the form with all the OnDirty events set?
 
N

NasaDBGuy

Thanks George,

I changed the sub into a function, and used the syntax you provided and
everything worked! I agree it would be simpler to run the textLoop()
procedure and just save the form as it is.

Thanks again for your help!

Marshall


George Nicholson said:
The following has worked for me for years when creating a form from scratch
(in Design view):
frm.BeforeUpdate = "=BlanketBeforeUpdate([ctlAddedBy])"
(Note: BlanketBeforeUpdate expects a Control for its argument, just like
your textValue procedure does.)

Therefore, I would try:
ctlLoop.OnDirty = "=textValue([" & ctlLoop.Name & "])"

I've never used a procedure, only Functions (that return a value) for this.
Not sure if there's a reason for that, but there might be. :) So, if you
run into problems, try changing textValue() into a function, even if all it
does is return True.

Not sure why you would want to do this every time the form loads however.
Why not just do it once and save the form with all the OnDirty events set?

--
HTH,
George


NasaDBGuy said:
Running Access 2003

I'm trying to loop through all the text boxes of my form to assign my user
defined sub when the dirty event occurs. Here' what I have so far:

public sub textValue(ctrl as control)
dim message as string
message = ctrl.value
msgbox = message
end sub

public sub textLoop()
dim ctlLoop as control

For each ctlLoop in Forms!spacecraft.form.controls
if typeof ctlLoop is textbox then
ctlLoop.OnDirty = "[textValue(ctlLoop)]" 'this line of code does not work
'when I fire the dirty event for that control Access tells me it is
looking
for a 'macro that does not exist.
end if
next ctlLoop
end sub


the textLoop() and textValue() subs are written in a module. I call the
textLoop sub when the form loads. spacecraft is the name of my form.

This is similar to code I got from access help on the OnUndo property:

Dim ctlLoop As Control

For Each ctlLoop In Forms(0).Controls
If ctlLoop.Type = acTextBox Then
ctlLoop.OnUndo = "[Event Procedure]"
End If
Next ctlLoop

Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top