You cannot use VBA variables in a control source expression.
Further, you talking about the forms on-load event (you cannot modify values
of BOUND controls in a forms on-open event).
And unless those VBA variables are declared at the MODULE level, they go out
of scope anyway.
So if you created the VBA variables in one routine (such as on-load or
on-open), then when the routine is finished, then the variable NO LONGER
exist and thus cannot supply values to controls.
I mean, this works:
Private Sub Form_Load()
Dim strV1 As String
strV1 = "='hello'"
Me.Text71 = strV1
End Sub
Of course the above just sets the control to a string value. (the control
can be bound to a column, or even be un-bound).
This also works:
Private Sub Form_Load()
Dim strV1 As String
strV1 = "='hello'"
Me.Text71.ControlSource = strV1
End Sub
So you can certainly change/set the control source to an expression, but
once again the expression cannot have any VBA variables.
The ONLY way what you have could have worked if the form was bound to a
query or table that had columns of the same name as those variables.
The previous application must have had a property called strMode (a column
from a table), or a control on the form.
And if the data source of a control is an expression, then you CAN NOT edit
those controls. So once the values were set then those controls could not
edit data but ONLY display? (right??).
Could/did you edit those controls on the form in the past when entering
data?
If you could edit those controls, then they were bound to a column - not a
VBA var.
>>>In Access 2010
= strMode ; Does not work
= PassVarValue(strMode) ; Does not work
= "Apple" ; This works
= PassVarValue ("Apple") ; This works
The above sounds 100% correct - no surprise.
And use of a bound control such as:
= PassVarValue ([Some Control Name]) -- this also should work.
You could in a PUBLIC module decleare this:
Public Function strMode() as string
strMode = some global VBA var
End Function
So you CAN pass a control value to the VBA fucntion as per above [FirstName]
or [strMode]. This assumes that FirstName or strMode exists as a control on
the form.
So while something in the past was working, it was NOT doing what you think
it was.
Fire up a machine with access 2000, and build a TINY test form that attempts
to do what you are thinking here - it will not work and never did. Just
place ONE text box on the form, and set the control source to your magical
supposed idea, and run it.
You either had some controls on the form with the same name as the VBA vars,
or something else was going on here.
Simply put:
What code you had before might have been running, but it was NOT doing what
you thought it did!!!
You cannot and NEVER could use VBA variables in a control source. You can
use other controls on the form, and public functions however.
Fire up Access 2000 on a machine. Create a blank form with one simple text
box. Now in the on-load attempt to set one variable and have a control with
an expression that supposed reference expression to that variable does not
work and NEVER could and NEVER did. (you have to start with a new form since
older existing forms have auto-generated properrties based on the original
table)
And hey if you CAN build such super duper simple form then you have the HUGE
JOY of throwing HUGE egg on my face in public here!
I been a Access MVP for 10 years, contributed to books on Access and was a
technical editor for Access 2010 Programmers reference. In other words,
would it not be cool to throw egg on me in public if you can create + build
such a simple form in Access 2000 that does what you say?
Remember – create a new Access 2000 database from scratch with Access 2000
and create that simple form with your variable and expression. You will find
it does not work. The end result here is your existing form code is not
doing what you think it is doing.
Best regards,
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada