Unbound control, testing its value

C

Chris

Do I have a case of Cerebral Flatulance?

An unbound control on my form has a value of true or false (checkbox)
assigned via VBA code.

How do I determine that value for VBA code and testing whether it is True or
False? Using "If Me.UnboundControl = True Then..." fails; its always null.

What am I missing? (BTW, I am very much an amateur Access-ite.)
 
D

Douglas J. Steele

I don't think you're missing anything: assuming the code is running in the
same form as UnboundControl, it should work. (I just cobbled together a
quick test to double-check)

You sure you're referring to the correct control?
 
C

Chris

Thanks for replying.

Yes, I have the ckbox visible and shows it is set to true when the form
opens.

My code is in an event. I've tried several events: Load, BeforeInsert,
Current...nada.

My code:

If Me.UnboundCheckBox= False Then
I do something
ElseIf Me.UnboundCheckBox= True Then
I do something else
ElseIf IsNull(Me.UnboundCheckBox.Value) Then
MsgBox "It is NULL"
EndIf

It returns null. What event should test for true/false properly?

I'm lost. See anything?

--
Thanks for your help,
Chris


Douglas J. Steele said:
I don't think you're missing anything: assuming the code is running in the
same form as UnboundControl, it should work. (I just cobbled together a
quick test to double-check)

You sure you're referring to the correct control?
 
K

Klatuu

I believe the problem is that it is an unbound control.
(copied from VBA Help) The DefaultValue property is applied only when you
add a new record.
Without further testing, I can't be sure whether add a new record would
affect unbound as well as bound controls; however, you may want to set the
intial value of the check box in the form open event.



Chris said:
Thanks for replying.

Yes, I have the ckbox visible and shows it is set to true when the form
opens.

My code is in an event. I've tried several events: Load, BeforeInsert,
Current...nada.

My code:

If Me.UnboundCheckBox= False Then
I do something
ElseIf Me.UnboundCheckBox= True Then
I do something else
ElseIf IsNull(Me.UnboundCheckBox.Value) Then
MsgBox "It is NULL"
EndIf

It returns null. What event should test for true/false properly?

I'm lost. See anything?
 
K

Klatuu

I did run a test with an unbound check box on a bound form. The Default
value was applied correctly. My original test was on an unbound form. So, I
am not sure why you are experiencing this problem, but perhaps using the Load
event to set the values will take care of the issue.

Chris said:
Thanks for replying.

Yes, I have the ckbox visible and shows it is set to true when the form
opens.

My code is in an event. I've tried several events: Load, BeforeInsert,
Current...nada.

My code:

If Me.UnboundCheckBox= False Then
I do something
ElseIf Me.UnboundCheckBox= True Then
I do something else
ElseIf IsNull(Me.UnboundCheckBox.Value) Then
MsgBox "It is NULL"
EndIf

It returns null. What event should test for true/false properly?

I'm lost. See anything?
 
C

Chris

I must have backed into the solution...have no clue, but it works now.

Thanks to you and Douglas.
 
Top