Is it possible to calculate and use calculated control names?

tranchemontaigne

Registered User.
Local time
Today, 14:17
Joined
Aug 12, 2008
Messages
203
I have never figured out how to calculate the name of a control and the use that calculated name to assign a value. Is this possible in MS Access 2000?

Pseudocode emulating the behavior of an option group or control array when a form is loaded is listed below.

Please consider "'t06_PHIN_System_Integrity" as a valid table field name to be passed to this function.

Private Function fn_PHIN_rdo_Buttons(strTableField As String)
'//16 Jan 2009
Dim strControlValue As String
Dim strControlNameYes As String
Dim strControlNameNo As String
Dim strControlNameUnk As String

strControlValue = "me![" & strTableField & "].value"
strControlNameYes = "Me![rdo" & Mid(strTableField, 10, 99) & "_Yes].value"
strControlNameNo = "Me![rdo" & Mid(strTableField, 10, 99) & "_No].value"
strControlNameUnk = "Me![rdo" & Mid(strTableField, 10, 99) & "_Unk].value"

Select Case strControlValue
Case "Y"
strControlNameYes = -1
strControlNameNo = 0
strControlNameUnk = 0
Case "N"
strControlNameYes = 0
strControlNameNo = -1
strControlNameUnk = 0
Case "U"
strControlNameYes = 0
strControlNameNo = 0
strControlNameUnk = -1
End Select
End Function

I am fully aware that this pseudocode fails to assign a value to a calculated control name because all it does is assign a value to a variable, then assign a second value to the same variable.

Any thoughts would be greatly appreciated.
________
Silver surfer vaporizer
 
Last edited:
I believe the trick you're looking for is:

Me("text" & 123) = -1

which would assign -1 to a control named text123.
 
this is promising - but something is still wrong

I tried executing the code

Me("rdo" & Mid(strTableField, 10, 99) & "_Yes") = -1

and now get the error "Microsoft Access cannot find the field [...] referred to in your expression"

The error is right because [...] is the name of a form control (option button/radio button) and not a field name.
________
FORD FN PLATFORM
 
Last edited:
That should work on the name of a control. I just tested on an unbound textbox. Is the button part of an option group? If so, you would give a value to the frame itself, not an individual option.
 

Users who are viewing this thread

Back
Top Bottom