Consulting

Results 1 to 4 of 4

Thread: Solved: display msgbox once

  1. #1

    Solved: display msgbox once

    how can I get my message box to display only one time after it has already been display?

    [VBA]If LenB(Range("B11").Value) > 0 Then
    If Year(frmPDCalc.Date1) <> Year(Range("B11").Value) Then
    frmPDCalc.Ent1.Enabled = False
    MsgBox "You may not register a FY" & Year(frmPDCalc.Date1) & " expense in a FY" & Year(Range("B11")) & " Expense Report Log.", vbExclamation, "PerDiem Traveler"
    End If
    End If
    [/VBA]

  2. #2
    VBAX Regular pike's Avatar
    Joined
    Dec 2007
    Location
    Alstonville, Australia
    Posts
    97
    Location
    Dude
    two possible ways
    One in the sheet module
    Option Explicit
    Private m_MsgBoxCancelled As Boolean
    Private Sub ValueStore()
        m_MsgBoxCancelled = True
    End Sub
    Sub testp()
    If LenB(Range("B11").Value) > 0 And Not m_MsgBoxCancelled Then
     Call ValueStore
             MsgBox "This works once"
    End If
    End Sub

    or use a cell B11 to store a value
    Sub testered()
    If LenB(Range("B11").Value) > 0 And Range("B11").Value = 0 Then
     Range("B11").Value = 1
             MsgBox "This works once"
    End If
    End Sub
    you can reset the B11 to 0 when you open the workbook

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    or use a static variable:[vba]Static AlreadyShown As Boolean
    If LenB(Range("B11").Value) > 0 Then
    If Year(frmPDCalc.Date1) <> Year(Range("B11").Value) Then
    frmPDCalc.Ent1.Enabled = False
    If Not AlreadyShown Then
    MsgBox "You may not register a FY" & Year(frmPDCalc.Date1) & " expense in a FY" & Year(Range("B11")) & " Expense Report Log.", vbExclamation, "PerDiem Traveler"
    AlreadyShown = True
    End If
    End If
    End If
    [/vba](untested). The message will show again (once) after the file is closed and re-opened.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    thank you both for you help!

    P45cal, your code works seamlessly great. thank you.

Posting Permissions

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