Checkbox to be false if Message field is Null

ScrmingWhisprs

I <3 Coffee Milk.
Local time
Today, 06:03
Joined
Jun 29, 2006
Messages
156
I have a checkbox (MessageIndicator) on my Edit Worker form that I would like to automatically be checked if there is text in my Message field. So if I edit this record and clear out the message field, that checkbox should uncheck itself when I save the record.

Code:
If IsNull(Me.Message) Then
    Me.MessageIndicator = False
    Else
    Me.MessageIndicator = True
    End If

I'm just not really sure where to put this code.

Thanks
ScrmingWhisprs
 
You could put it in the AfterUpdate event of the message field.
 
I have the same type of thing in my DataBase and it works fine in the After Update event.
 
So this is the code I have for the After Update event of my message field. This works great when a message is added to a worker record, i.e. the checkbox gets checked because the field is not null. However, when a message is cleared, and the field is null, the checkbox does not get unchecked.


Code:
Private Sub Message_AfterUpdate()
    If Not IsNull(Me.Message) Then
    Me.MessageIndicator = True
    Else
    Me.MessageIndicator = False
    End If
End Sub

Help!
SW
 
Anytime you conditionally do something (such as setting the checkbox based on the message field, you have to include the same code in the Form_Current sub. This allows Access to check for the condition as you move from record to record and set each record accordingly.

Code:
Private Sub Form_Current()
If Not IsNull(Me.Message) Then
 Me.MessageIndicator = True
Else
 Me.MessageIndicator = False
End If
End Sub
 
So this is the code I have for the After Update event of my message field. This works great when a message is added to a worker record, i.e. the checkbox gets checked because the field is not null. However, when a message is cleared, and the field is null, the checkbox does not get unchecked.
When a message is cleared it isn't null, but an empty string, so:

Code:
Private Sub Message_AfterUpdate()
    If IsNull(Me.Message) OR Me.Message = "" Then
       Me.MessageIndicator = False
    Else
       Me.MessageIndicator = True
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom