Enabling/Disabling Controls on a form

David Mack

Registered User.
Local time
Today, 00:56
Joined
Jan 4, 2000
Messages
53
Hello all!

I have a form with 58 question option boxes. I test whether the data entry person has filled out all the required information in the form header prior to allowing them to answer the questions.

If the required info is not entered, I want to disable the question controls. If completed, then enable the controls. The controls are named: [1], [2], ... , [58]

I figured a loop would work. Initially I tried:

Dim I As Integer
For I = 1 to 58 Step 1
Me!.enabled = False
Next I

If I hard code Me![1].enabled = False, the first control is disabled. I then tried to create the string:

Dim strControl As String
Dim I As Integer
For I = 1 to 58 Step 1
strControl = "Me![" & I & "].Enabled =False"
Debug.Print strControl
Next I

The results in the debug window look fine.

1) How could I either pass the "I" variable into the Me! statement, or how could I execute the string I created?

Dave


[This message has been edited by David Mack (edited 11-15-2000).]
 
David, I think the problem is your naming of the control to a single numeric value. This is confusing Access into thinking you are working with an Array or that you want to use the value to loop through the control collection (not what you want). I think the fix to the problem is to add an Alfa character to the control name of each control so Access does not get confused. In the example below I added "opt" to the existing control name (ei...opt1, opt2, opt3...all the way to...opt58).

Then change your code to:

Dim i As Integer
For i = 1 To 58
Me("opt" & i).Enabled = False
Next i

This should fix the problem.

HTH
RDH

[This message has been edited by R. Hicks (edited 11-15-2000).]
 
Your theory is correct. Works like a charm!

I guess the name of the column really is confusing Access. I tried all kinds of quotes and pics to no avail. I could not understand what the heck was happening.

The reason I named all the question columns with a number is because I use several loops to evaluate the contents of each column for statistical reasons. I could have easily named them q1, q2, q3, ..., q58 and just concatenated the "q" in my loops.

As me emulating the name of the control to be the same as the source column, I should have stuck with the conventions and named them opt1, opt2...opt58 for consistancy and readability.

I thank you so much for your time!

HTH!!!

Dave

[This message has been edited by David Mack (edited 11-16-2000).]
 
There's another way that doesn't rely on common field names. Use the "Tag" property to give a common group name to all of the fields that you want to enable/disable. In this example, they are tagged "Test_Quest". Then use some code like this:

Dim frmMyForm As Form
Dim ctlMyCtls As Control
Set frmMyForm = Forms!fMyWonderfulForm

'additional code here

' To turn on the whole group:
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "Test_Quest" Then
ctlMyCtls.Visible = True
ctlMyCtls.Enabled = True
End If
Next ctlMyCtls
' do whatever else
Set frmMyForm = Nothing
 
"Pretty Cool Stuff" Chris. I had not tried this approach, but it works. I can visualize using this in the future.

RDH
 

Users who are viewing this thread

Back
Top Bottom