Home > Mobile >  How to set/manipulate an unbound Option Group in MS Access?
How to set/manipulate an unbound Option Group in MS Access?

Time:07-14

I made an Unbound Option Group in my Form that looks like this:

enter image description here

Its Option Values are 1 for Available, 2 for Reserved, 3 for Unavailable and named as check1, check2, check3 respectively. In my function below (User clicks the List/Table):

Private Sub listBooks_AfterUpdate()

    BookModule.setBookStatus status:=Me.listBooks.Column(6), check1:=Me.check1, check2:=Me.check2, check3:=Me.check3
    'Debug.Print Me.check1.Value
    
End Sub

where method setBookStatus is defined as:

Public Sub setBookStatus(status As Integer, check1 As CheckBox, check2 As CheckBox, check3 As CheckBox)
    
    If status = 1 Then
        check1.Value = True
        check2.Value = False
        check3.Value = False
    End If
    
    If status = 2 Then
        check1.Value = False
        check2.Value = True
        check3.Value = False
    End If
    
    If status = 3 Then
        check1.Value = False
        check2.Value = False
        check3.Value = True
    End If
    
End Sub

But upon running I am getting this error:

Run-Time error '2448':

You can't assign a value to this object.

If I execute this ?Me!MyCheckBox.Value or ?Me!MyCheckBox in my Immediate Window, I am getting this:

Compile error:

Variable not yet created in this context

Hope someone can help me with what I am missing.

CodePudding user response:

An option group is linked. You set and get it as a whole, and don't manipulate the individual checkboxes. They automatically get checked/unchecked

The sub could be as simple as:

Public Sub setBookStatus(status As Integer, optGroupFrame As OptionGroup)
   optGroupFrame = status
End Sub

Or, of course, omitted altogether since you don't need subs to replace single simple lines of code.

If you do want to manipulate individual checkboxes, well, don't use an option group.

  • Related