Consulting

Results 1 to 5 of 5

Thread: IF Formula Using Label

  1. #1
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location

    IF Formula Using Label

    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,

    Golf

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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.

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hi, Golf. Check my signature for how to post your VBA code.
    ~Anne Troy

  4. #4
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location
    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
    DoEvents
    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,

    Frank

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Glad to help

    Take Care

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •