View Full Version : Message Box Onclick Event
mattster1010
07-22-2008, 03:08 AM
Hi All,
I have written the following code to populate a message box if a textbox has a null value, the code executes when check96 is clicked:
Private Sub Check96_Click()
If Me!Frm_Timesheet_Capture_1!Week_Ending = Null Then
MsgBox "Please enter a week ending date", vbOKOnly, "System Message"
End If
End Sub
When the tickbox is clicked nothing happens, even though the textbox is null...
Am I doing something wrong?
CreganTur
07-22-2008, 05:26 AM
At first glance I'd say it's because you're not declaring Null correctly.
Is Frm_Timesheet_Capture_1 the name of the form where the textbox is? I'm asking because you're also using 'Me', which automatically refers to the current, active form without having to declare its name. So if Frm_Timesheet_Capture_1 is the name of the form that this code is behind, then you only need to use 'Me.Week_Ending' for correct syntax.
Try:
Private Sub Check96_Click()
If IsNull(Me.Week_Ending) Then
MsgBox "Please enter a week ending date", vbOKOnly, "System Message"
End If
End Sub
Also, when you're working with Form objects you want to use the dot (.) instead of the bang (!)- the reason is that using a bang disables intellisense (the cool tool that shows you options as you write functions).
When the tickbox is clicked nothing happens
Behind the on_click event for the checkbox you're probably going to want to add a little more to your code, because I'm guessing that you only want the code to run when the checkbox is checked. So you would use:
Private Sub Check96_Click()
If Me.Check96 = True Then
If IsNull(Me.Week_Ending) Then
MsgBox "Please enter a week ending date", vbOKOnly, "System Message"
End If
End If
End Sub
This runs your evaluation code only when the checkbox has a checkmark in it. Otherwise, if you don't use this extra code, then your evaluation code will run again if you uncheck the checkbox.
HTH :thumb
mattster1010
07-22-2008, 07:53 AM
Thanks CreganTur, thats was a big help.
mattster1010
07-22-2008, 08:03 AM
Hi CreganTur,
Sorry to bother again,
How would you reference is not null in the VBA vode?
Would it be NotNull?
CreganTur
07-22-2008, 08:21 AM
It's no bother at all :)
This example displays 2 different messages; 1 for Null textbox, another if not null. Create a form with a single textbox named txtBox, and add this code behind a button click. Click the button with an empty textbox, then add some text and click again.
If IsNull(Me.txtBox) Then
MsgBox "It's empty!"
ElseIf Not IsNull(Me.txtBox) Then
MsgBox "It has a value."
End If
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.