View Full Version : Solved: IF Formula Using Label

08-31-2004, 08:13 PM
Hi, everyone -

I'm not real sure this is possible, but I figured you guys would know.

I am currently using the code below using two (2) labels within my splash screen to show the current date and time. What I'm wondering is whether there is a way to construct an IF formula using Label1 in the formula. For example, ...... IF Label1< 10/1/2004, play a specific wav file; IF Label1> 10/1/2004, "". In which code string would I include the method?

Private Sub UserForm_Initialize()
Label1.Caption = Format(Now, "mmmm dd, yyyy")
Label2.Caption = Format(Now, "h:mm:ss AM/PM")
End Sub

Private Sub UserForm_Activate()
Application.OnTime Now + TimeValue("00:00:06"), "KillTheForm"
End Sub

Thanks for the help,


Jacob Hilderbrand
08-31-2004, 08:30 PM
You can do something like:

Date2 = DateSerial(2004, 10, 1)
If Date > Date2 Then
MsgBox "Play A Sound"
End If

Date2 is the date you set. Date is todays date (The same as Now, but without the time).

No need to even mess with the label caption, just set the caption to the date, and use the date in further calculations as needed.

Anne Troy
08-31-2004, 08:47 PM
Hi, Golf. Check my signature for how to post your VBA code. :)

08-31-2004, 09:48 PM
Hi, Jacob and Dreamboat -

Thanks for the help. I've kind of tinkered with your code, Jake, and seems to work great now.

Private Sub UserForm_Activate()
Date2 = DateSerial(2004, 10, 1)
If Date < Date2 Then
Sheets("data_entry_sheet").Unprotect ("led52not")
Application.ScreenUpdating = True
ActiveSheet.Shapes("object 258.wav").Select 'warning error msg'
Selection.Verb Verb:=xlPrimary
Sheets("data_entry_sheet").Protect ("led52not")
End If
Application.OnTime Now + TimeValue("00:00:10"), "KillTheForm"
End Sub

Thanks again for the help,


Jacob Hilderbrand
08-31-2004, 10:26 PM
Glad to help

Take Care