Reputation: 471
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.
Upvotes: 1
Views: 123
Reputation: 97101
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.
Upvotes: 1
Reputation: 91316
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.
Upvotes: 0