Option Button: conditional enable/disable

BC77

New member
Local time
Tomorrow, 00:49
Joined
Sep 9, 2007
Messages
3
Hi,

I have a table "tblTestStatut" where each column indicates the statut of one test.
Each column is related to an option group of four option buttons in a form "frmEvaluation".

I would like enable or disable these option buttons depending of the value of the option group.

A solution would consist in writing a particular code for each test (example for two tests: Bryden and BostonNaming).

Code:
Private Sub Form_Current()

If Me.Bryden_Frame = "" Or Me.Bryden_Frame = 0  _
Or Me.Bryden_Frame = 1 Then
    Me.Option_Bryden_0.Enabled = True
    Me.Option_Bryden_1.Enabled = True
    Me.Option_Bryden_3.Enabled = False
ElseIf Me.Bryden_Frame = 2 Or _
Me.Bryden_Frame = 3 Then
    Me.Option_Bryden_0.Enabled = False
    Me.Option_Bryden_1.Enabled = False
    Me.Option_Bryden_3.Enabled = True
End If

If Me.BostonNaming_Frame = "" Or Me.BostonNaming_Frame = 0 _
Or Me.BostonNaming_Frame = 1 Then
    Me.Option_BostonNaming_0.Enabled = True
    Me.Option_BostonNaming_1.Enabled = True
    Me.Option_BostonNaming_3.Enabled = False
ElseIf Me.BostonNaming_Frame = 2 _
Or Me.BostonNaming_Frame = 3 Then
    Me.Option_BostonNaming_0.Enabled = False
    Me.Option_BostonNaming_1.Enabled = False
    Me.Option_BostonNaming_3.Enabled = True
End If

End Sub

As my data base will contain a lot of tests, I have write the following code:

Code:
Private Sub Form_Current()

Dim db As Database, rsTestStatutTable As Recordset
Dim varColumnTotal As Integer, varColumnFocus As Byte
Dim Test As Field, TestStatutFrame As String
Dim OptionTestStatut0 As String, OptionTestStatut1 As String
Dim OptionTestStatut2 As String, OptionTestStatut3 As String

Set db = CurrentDb
Set rsTestStatutTable = db.OpenRecordset("tblTestStatut")

[I]' Find the record of tblTestStatut bound to the current[/I]

record of tblEvaluation
rsTestStatutTable.MoveFirst

Do Until rsTestStatutTable!Eva_ID = Me!Eva_ID
rsTestStatutTable.MoveNext
Loop

[I]' Count the column(s) number of rsTestStatutTable
' {= Number of tests + one ID column}[/I]

varColumnTotal = rsTestStatutTable.Fields.Count

[I]' Focus and the second column of rsTestStatutTable
' {= the first test name}[/I]

varColumnFocus = 1

Do Until varColumnFocus > varColumnTotal - 1
    Set Test = rsTestStatutTable.Fields(varColumnFocus)

    TestStatutFrame = Test.Name & "Statut_Frame"
    OptionTestStatut0 = "Option_" & Test.Name & "Statut_0"
    OptionTestStatut1 = "Option_" & Test.Name & "Statut_1"
    OptionTestStatut3 = "Option_" & Test.Name & "Statut_3"

    [I]' Enabled the option buttons depending of statut test[/I]

    If Me(TestStatutFrame) = "" Or Me(TestStatutFrame) = 0 _
    Or Me(TestStatutFrame) = 1 Then
        Me(OptionTestStatut0).Enabled = True
        Me(OptionTestStatut1).Enabled = True
        Me(OptionTestStatut3).Enabled = False
    ElseIf Me(TestStatutFrame) = 2 _
    Or Me(TestStatutFrame) = 3 Then
        Me(OptionTestStatut0).Enabled = False
        Me(OptionTestStatut1).Enabled = False
        Me(OptionTestStatut3).Enabled = True
    End If

varColumnFocus = varColumnFocus + 1
Loop

End Sub

It seems that VBA does not accept the code:

Code:
Me(OptionTestStatut0).Enabled = True

whereas it accepts:

Code:
If Me(TestStatutFrame) = "" … Then


I don't understand why… Can you help me ?
 
Ah but... I see now you have already got that.

What you are trying to do you do is pass the name of the option group button via a variable ..... yes?

Yes, it is what I try to do... since days!
 
Pass the name of an option group button via a variable with the function "enabled" is it an impossible thing in VBA for Access ?
 

Users who are viewing this thread

Back
Top Bottom