If field is not null then checkbox = true

james_IT

Registered User.
Local time
Today, 21:00
Joined
Jul 5, 2006
Messages
208
Hi guys

feeling a bit stupid today as i cant figure this out and its pretty simple.

i want my checkbox (Exchanged) to be ticked if a date field (ExchangeDate) has had a date put into it. otherwise remain false/empty.

ive tried an if function on the after update event of the field (ExchangeDate) but cant seem to get it to work so far :confused:. i also put the code in the forms on current event but no luck.

Private Sub ExchangeDate_AfterUpdate()
If IsNull(Me.ExchangeDate) Then
Me.Exchanged = False
Else
Me.Exchanged = True
End If
End Sub

note: i have a button that brings up a calendar and inputs the date into the ExchangeDate field. i dont think this should make any difference should it?

Any pointer in the right direction is appreciated
 
Last edited:
Try putting a break point at the start of the If statement and then see what value your field ExchangeDate is holding under various conditions and then you will know what to test for.
 
Try putting a break point at the start of the If statement and then see what value your field ExchangeDate is holding under various conditions and then you will know what to test for.

thanks. ive added a breakpoint so it stops the code at that point. i still cant see a problem as it all looks ok. any other suggestions or pointers?
 
...i have a button that brings up a calendar and inputs the date into the ExchangeDate field. i dont think this should make any difference should it?
Yes it does! Most events (such as AfterUpdate) attached to controls such as textboxes only fire if data is physically entered into them, which is to sat typed in or pasted in. Populating them thru code, such as using a popup calendar, does not fire these events! In order to get the AfterUpdate to fire you'd have to explicitly Call the dub.

Linq ;0)>
 
Yes it does! Most events (such as AfterUpdate) attached to controls such as textboxes only fire if data is physically entered into them, which is to sat typed in or pasted in. Populating them thru code, such as using a popup calendar, does not fire these events! In order to get the AfterUpdate to fire you'd have to explicitly Call the dub.

Linq ;0)>
Beat me to it, Just dawned on me that that was the problem :o
 
sorry, realised you meant explicitly call the 'sub'. I know this involves writing 'call' somewhere but im not sure where? please advise.

also do i need to put the code in the forms oncurrent event?
 
You wouldn't need any events if you have a checkbox who's control source is

= Not IsNull([ExchangeDate])

(you shouldn't be storing the results of the checkbox anyway as that violates the rules of normalization)
 
thanks guys and thanks bob - i have taken that on board and removed the yes/no from the table so as not to store these results...
 
thanks guys and thanks bob - i have taken that on board and removed the yes/no from the table so as not to store these results...

yes - you dont need it in the table - although it may well be useful as a fast aide-memoire to your users.

even better - have a "errors query" that just selects those rows with a NULL date.
 

Users who are viewing this thread

Back
Top Bottom