Checkbox woes

elyleeboy

Registered User.
Local time
Today, 00:37
Joined
Sep 9, 2004
Messages
20
I have created an event proceedure attached to a drop down list, and when the value changes, I have created the following code:

If QuestionType = "TF" Then
For j = 1 To 5
If j < 3 Then
Me.Controls("Correct" & j).Enabled = True
Else

Me.Controls("Correct" & j).Enabled = False
Me.Controls("Option" & j).Enabled = False
End If
Next j
Option1.Value = "True"
Option2.Value = "False"
Option3.Value = " "
Option4.Value = " "
Option5.Value = " "
Else
For j = 1 To 5
Me.Controls("Correct" & j).Enabled = True
Me.Controls("Option" & j).Enabled = True
Next j
End If


Hope thats all OK however, I am trying to include the following:

Me.Controls("Correct" & j).Value = False

I run the database the first time and everything works OK, but when I close I get an error message:

See attached file.

I run the debug, which the highlights the following:

Option1.Value = "True"


Hope you can help!!!!
 

Attachments

  • Err.jpg
    Err.jpg
    23.2 KB · Views: 135
What kind of controls are you referring to with: "Correct" & j

???
kh
 
They are checkbox controls
 
me!Option1.Value = "True"


???
kh
 
me!Option1.Value = "True"

??

I think I need to make myself a bit clearer.

Option(1-5) is a text box controls.
Correct(1-5) are checkbox controls.

The following code is where I'm having the problem (Stuff in orange):

Private Sub Form_Open(Cancel As Integer)

If QuestionType = "DD" Then
For j = 1 To 5
Me.Controls("Drop" & j).Enabled = True
Me.Controls("Correct" & j).Enabled = False
Next j
Else
For j = 1 To 5
Me.Controls("Drop" & j).Enabled = False
Me.Controls("Correct" & j).Enabled = True
Next j
If QuestionType = "TF" Then
For j = 1 To 5
If j < 3 Then
Me.Controls("Correct" & j).Enabled = True
Else
Me.Controls("Correct" & j).Value = False
Me.Controls("Correct" & j).Enabled = False
Me.Controls("Option" & j).Enabled = False
End If
Next j
Option1.Value = "True"
Option2.Value = "False"
Option3.Value = " "
Option4.Value = " "
Option5.Value = " "
Else
For j = 1 To 5
Me.Controls("Correct" & j).Enabled = True
Me.Controls("Option" & j).Enabled = True
Next j
End If
End If
End Sub
 
Dim j As Integer
j = 6
Me.Controls("Check" & j).Value = False


This works on my side. Maybe you need to dim j?

???
kh
 
Thanks for your patience:

Could you show me how you incorporated the dim and what the dim does please?

(I'm a complete newbie if you hadn't guessed!)
 
Can you actually set a value to an object. ie make a checkbox checked depending on a decision?

eg.

Me.Option1.Value = "True"

would that actually work?
 
Sure. Try it. If you can't get it to work, re-post...

kh
 
Private Sub Form_Open(Cancel As Integer)
dim j as integer
If QuestionType = "DD" Then
For j = 1 To 5
Me.Controls("Drop" & j).Enabled = True
Me.Controls("Correct" & j).Enabled = False
Next j
Else
For j = 1 To 5
Me.Controls("Drop" & j).Enabled = False
Me.Controls("Correct" & j).Enabled = True
Next j
If QuestionType = "TF" Then
For j = 1 To 5
If j < 3 Then
Me.Controls("Correct" & j).Enabled = True
Else
Me.Controls("Correct" & j).Value = False
Me.Controls("Correct" & j).Enabled = False
Me.Controls("Option" & j).Enabled = False
End If
Next j
Option1.Value = "True"
Option2.Value = "False"
Option3.Value = " "
Option4.Value = " "
Option5.Value = " "
Else
For j = 1 To 5
Me.Controls("Correct" & j).Enabled = True
Me.Controls("Option" & j).Enabled = True
Next j
End If
End If
End Sub
 
Just stumbled on something that may be significant.

if I use: Me.Controls("Correct" & j).Value = False

in a Private Sub Form_Open(Cancel As Integer)

it doesn't work.

Yet in: Private Sub QuestionType_Change()

it works fine???
 
The form probably has to be past the open event before you can ref an object on it...

???
kh
 
Can you make it small enough to zip and post here?

kh
 
Try putting your code in the got focus event.


???
ken
 
After a bit of tinkering...! That seems to have done the trick!

Thanks very much :D
 

Users who are viewing this thread

Back
Top Bottom