Calling a Sub Procedure Within a Form Based On a Variable

G

Guest

I am trying to call a sub procedures based on the current textbox. The
situation is this; my database receives input from a scale and places the
weights directly into the textbox with the focus. The scale communicates
using MsComm's OnComm event. However, this does not run the
Textbox_AfterUpdate procedure that needs to be run (I don't know why). Since
there are many textboxes that receive weights from the scale, I need it to
run the correct AfterUpdate procedure.

So far I have tried :

dim strTextbox as String
strTextbox = me.ActiveControl.Name & "_AfterUpdate"
call strTextbox

That did not work because access requires a sub procedure so I tried:

dim strTextbox as String
strTextbox = me.ActiveControl.Name & "_AfterUpdate"
application.run strTextbox

This does not work; I guess, because the form is not a public class and the
procedure also is not public.

I might also add that the form that gets the input is a subform.

I need to solve this problem one of two ways. 1, the text box recognizes
that it has been updated and therefore, runs the appropriate sub
automatically; or 2, the OnComm can call the appropriate AfterUpdate
procedure. Any help will be greatly appreciated.
 
D

Douglas J. Steele

Why not have a generic routine, and pass it information such as which
textbox is relevant? (Actually, you should be able to use the
Screen.ActiveControl or Screen.PreviousControl properties to determine that,
so passing an argument might not be necessary)

Make the generic routine a function, and then set the AfterUpdate property
of each of the text boxes to that function. Remember that you can set the
properties for multiple text boxes at once if you've selected all of the
text boxes, and then go to the Properties dialog.
 
G

Guest

A generic function has a couple of problems with it. 1, the after update for
each textbox does different things. Some check to make sure that the scale
was zeroed and at a gross 0. Others record the weight displayed and check to
make sure that it is within the acceptable tolerance which is also different
for each textbox. Then other textboxes make sure that the scale is tared at
0 on a net weight. Also to make it go to a general function and go through a
select case statement for each text box would be horrendous considering there
are 12 separate text box all with their unique functions. This database will
unfortunately be run on P3 450 mhz computers (company to cheap to upgrade
production computers) so saving processing speed is very important thus I
would like to minimize calls to other functions and case statements.

If I misunderstood what you were trying to tell me, please let me know. I
am thankful for the quick reply. If I can get the program to call the
correct afterupdate function directly all my problems will be solved.

Thank you very much for your reply.

Regulator
 
D

Douglas J. Steele

I don't see why "a select case statement for each text box would be
horrendous". You've already (presumably) written the code for each of the 12
separate text boxes. Worst case is that you leave the code you've already
written, and use:

Select Case Screen.ActiveControl.Name
Case "Text1"
Call Text1_AfterUpdate()
Case "Text2"
Call Text2_AfterUpdate()
Case Else
MsgBox "Sorry: I don't what to do for " & _
Screen.ActiveControl.Name
End Select

(Better, of course, would be to copy the appropriate code from each of the
12 routines into the appropriate Case blocks)

The overhead of the intermediary routine should be minimal.
 

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