1

I have a form in access that has a series of questions. Each question has a frame with three radio buttons with each radio button designating a different selection (for ease 1, 2, 3). I have added a question to this form and would like for some way to designate all of the records prior to the change to be exempt from this field. I thought I could set the value of this field in the previous records to -1 to signify that they are exempt. But now I don't know how to essentially disable this question on the previous records.

0

2 Answers 2

1

Not sure how well I understand your description, by my hunch is the form's current event could be useful here.

Private Sub Form_Current()
    Me.ControlName.Enabled = Not Me.indicator_field = -1
End Sub

If ControlName should be Enabled for new records, you can use the Nz() function to handle the initial Null.

Me.ControlName.Enabled = Not Nz(Me.indicator_field, 0) = -1

You could also manage ControlName 's Locked property instead of or in addition to Enabled. The combinations alter the control's appearance in different ways. See which you prefer.

There may be other details I overlooked, but hopefully that gives you a useful starting point.

If your form contains text boxes in a sequence such as Text1, Text2, ... Textn, you can use a For loop to do something with each of them ... enable/disable or whatever ... I'll use Debug.Print because it's easy for me.

Dim i As Long
Dim strCtl As String
For i = 1 To 10
    strCtl = "Text" & CStr(i)
    Debug.Print Me.Controls(strCtl).Name
Next i

The key there is you can use your string variable to refer to a specific member of the form's Controls collection. Then do what you need with it, instead of printing its .Name property.

3
  • Do you know if there is an easy way to loop through elements on a screen to do this for multiple fields of the same name but numerically ordered?
    – B-Ray
    Jul 12, 2012 at 22:00
  • What do you mean by numerically ordered: Text1; Text2; Text3; etc?
    – HansUp
    Jul 12, 2012 at 22:11
  • That is what I mean precisely.
    – B-Ray
    Jul 12, 2012 at 22:13
0

You can refer to the NewRecord property:

Private Sub Form_Current()
     If Me.NewRecord = True
        Then Me.MyControl.Enabled = True
     Else
        Then Me.MyControl.Enabled = False
     End If
End Sub

Or using your new field, you can say:

If Me.MyField = -1
    Then Me.MyControl.Enabled = False
 Else
    Then Me.MyControl.Enabled = True
 End If

It is nearly always a good idea to include a datetime of creation in MS Access tables.

1
  • These records get revisited several times. So there will be a point when it is not a new record and will be opened back up again.
    – B-Ray
    Jul 12, 2012 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.