Check box when data entered

The Bey

Registered User.
Local time
Today, 08:52
Joined
Jun 21, 2011
Messages
84
Ok I can't imagine this being hard.

I want a checkbox to be "checked" when a date is entered into a textbox, so, "If .. = True, checkbox = True" or such and such

What code do I need for this?
 
If .. = True then checkbox = -1 else checkbox = 0

-1 for YES in a Yes/No Checkbox

Cheers
Goh
 
To set the value of a control's control source to some appropriate value: MyControl=TheValue

To run some code after a controls content has been changed (by the user!): use the control's AfterUpdate event

And finally: to set a checkbox if a date has been entered is in some ways redundant, in that the date field is no longer null, and hence the checkbox info is a reflection of an already known fact in that can be derived from the record.

And as to the possible values for a checkbox, True or False works just fine.
 
Thanks for the response but what I was interested in was how to classify the date box.

I want to use something that'll say "If this box has anything in it, do this"; would it be something along the lines of anti-null (lack of a better term)

And as for the check box being invalid, thanks. Didn't actually see that but you made me realise I was going about it twice for no reason!

This is the code that I found that mentioned the check box and I was going to do another take on it:

Private Sub YourTickBoxName_AfterUpdate()
If Me.YourTickBoxName = -1 Then
Me.Field1 = Date
Me.Field2 = DateAdd("yyyy", 3, Date)
Else
Me.Field1 = Null
Me.Field2 = Null
End If
End Sub
 
Thanks for the response but what I was interested in was how to classify the date box.

I want to use something that'll say "If this box has anything in it, do this"; would it be something along the lines of anti-null (lack of a better term)

And as for the check box being invalid, thanks. Didn't actually see that but you made me realise I was going about it twice for no reason!

This is the code that I found that mentioned the check box and I was going to do another take on it:

Private Sub YourTickBoxName_AfterUpdate()
If Me.YourTickBoxName = -1 Then
Me.Field1 = Date
Me.Field2 = DateAdd("yyyy", 3, Date)
Else
Me.Field1 = Null
Me.Field2 = Null
End If
End Sub

I believe that's saying that when the box is ticked the the text box will be filled in with date.

Something like this may help:
On the text box, right click, properties, format tab, format, short date

Then

Event tab, after update, elipsis (...) dots on the side, code builder

Code:
Private Sub [I]TEXT_BOX_NAME[/I]_AfterUpdate ()

If Me.[I]TEXT_BOX_NAME[/I] = "[I]Whatever you want it to equal before checking the box[/I]"
Then
Me.[I]Check_BOX_NAME[/I].Value = -1
Else
Me.[I]Check_BOX_NAME[/I].Value = 0

End If

End Sub

If someone else suggests a way do it theres, i'm learning too.. just trying to help as i learn :)
 
Last edited:
Yeah that's what it's saying and I was going to do it so that if you have a date in the textbox, the checkbox will be "True" or "-1" then a seperate box will check if the box is marked as true and if it is then another command will happen.

I need to know what to type just to tell the program to run an expression if there is something in the box, maybe something to do with a String
 
Ok so I managed to get it working by scrappping the check box and instead used the IsDate function, thus saying "If this is a date, add this amount of time on" but what I've found to be a pain is that I can only get it to calculate the date from today's date.

How can I get it to take into account the date that is in the box, as it may not be today's date, and also can I change it to take the date as a decimal rather than a double?
 
You had this in your example.
Code:
Me.Field2 = DateAdd("yyyy", 3, Date)

Try this instead
Code:
 Me.Field2 = DateAdd("yyyy", 3, [I]me.yourdatefield[/I])

The last part of a dateadd command is the date to compare it to. it does not have to be the actual date.

hope that helps
 

Users who are viewing this thread

Back
Top Bottom