Changing the state of a checkbox?

Mermogoat

Registered User.
Local time
Today, 07:51
Joined
Dec 1, 2002
Messages
36
In my form I have this code as the Dirty event of text box named "Completed." Complete is the checkbox):

Private Sub Completed_Dirty(Cancel As Integer)
If Me![Completed] = "" Then
Me![Complete].Value = False
Else
Me![Complete].Value = True
End If
End Sub

So basically when the person clears the text box, it will uncheck the checkbox, and when they enter data into it it will become checked.

What's wrong with this code? Thanks in advance for the help
 
Hi

Maybe you can put the code in the Completed textbox
AfterUpdate event.

This event will fire after user exit the textbox to another field or control.


Hope it help.:D
 
I did not think Dirty was an event, but maybe I am wrong... See if this works in any case:

Code:
Private Sub Completed_AfterUpdate(Cancel As Integer)
If Me![Completed].Dirty = True Then
Me![Complete].Value = False
Else
Me![Complete].Value = True
End If
End Sub

Also in your original code, change the second line from:

Code:
 If Me![Completed] = "" Then

To:

Code:
 If Me![Completed].Text = "" Then

Again I do not think this will work, but let us know.

:)
 
Mr.Bank is right and maybe can try use this to test whether there is any text in the textbox:

IF ISNull(Me!Completed) then
Me!CheckBox = False
else
Me!CheckBox = True
end if


Hope it works. Please let us know

Cheers

mderby;)
 
I just looked it up for the sake of it, Dirty is an object property, and not an event. Hope this helps a little :)
 
Hmm...On Dirty is listed as one of the events. it says its used before a record is modified or something. I'm using Access 2002, btw. Anyway, thanks for the help and God bless
 

Users who are viewing this thread

Back
Top Bottom