Resolve Dynamic Reference

dlc9ball

New member
Local time
Today, 13:42
Joined
Feb 12, 2007
Messages
2
Hello. If anyone can help me out, I would greatly appreciate it!
I'm using Access 2000.

I have created a form with 60 text boxes side by side to represent a
large "status bar". The code works great for 20 text boxes, but
when I copy the code for the other 40 Cases (each case representing a
text box for a total of 60 Cases), the program is too large to
compile. 64k is the limitation. My program is around 153k.


My first thought was to call the code (shown above for the first Case)
60 times. The problem is that I can't figure out how to dynamically
reference the text boxes via...


t1.BackColor = c_Blue 'works fine, but not in a called program


t1 thru t60 reference the text boxes.


I have managed to pass the Task, the color, and the Bartime with no
problem.


Here is the definition of the module I copied the code to...


Static Function Progression(Task As String, Interval As TextBox, Color
As Double, BarTime As Integer)


Here is the call to the function...
...
Dim t1 As TextBox
Call Progression("Start Wash-up", t1, c_Blue, BarTime)


...then in the called program - Progression...


Static Function Progression(Task As String, Interval As TextBox, Color
As Double, BarTime As Integer)
Forms![frm_MakeReady_150]![CurrentTask] = Task
Forms![frm_MakeReady_150]![CurrentTask].BorderColor = Color
Forms![frm_MakeReady_150]![CurrentTask].ForeColor = Color
Do While Holdrun < BarTime
DoEvents
Set tblHold = MyDB.OpenRecordset("tbl_Hold", DB_OPEN_TABLE)
If Not tblHold![Complete] Then
If Not tblHold![Paused] Then
Forms![frm_MakeReady_150]![Interval].BackColor = Color


...here is where it blows up. The error message is...
Run-time error '2465':
Microsoft Access can't find the field 'Interval' referred to in your
expression


If I place my cursor over [Interval] in the function definition...it
displays as... Interval = Nothing


I've tried defining Interval as other types, but nothing is working.
No matter what, I can't get it to reference the "contents" of
Interval... t1...rather than "Interval".


If I define Interval as String and place my cursor over [Interval] in
the function definition...it displays as... Interval = "t1", but
again, it is looking for "Interval" rather than its contents...t1.


Please explain how to define [Interval] in the calling program and the
called program and also how to code the reference to [Interval] in the
called program to interpret the contents of [Interval] to change the
color...


Forms![frm_MakeReady_150]![Interval].BackColor = Color


Thank You.
 
...
Dim t1 As TextBox
Call Progression("Start Wash-up", t1, c_Blue, BarTime)

...then in the called program - Progression...

Static Function Progression(Task As String, Interval As TextBox, Color
As Double, BarTime As Integer)

Forms![frm_MakeReady_150]![Interval].BackColor = Color


Thank You.

Kill the Dim t1 as TextBox line
Pass in t1 as a string rather than a textbox
e.g. Call Progression("Start Wash-up", "t1", c_Blue, BarTime)

Then, in your function, change it to expect a string rather than a textbox
e.g. Static Function Progression(Task As String, Interval As String, Color
As Double, BarTime As Integer)

Then you can reference everything from the Interval variable.
e.g.
Forms("frm_MakeReady_150").Controls(Interval).BackColor = Color

Regards,
Pete.
 
Thank you so much, Pete. Your code worked great! :)
 

Users who are viewing this thread

Back
Top Bottom