none
Msgbox display on current form only once RRS feed

  • Question

  • This should be simple, but I can't make it work:

    I want to display a simple MsgBox when a form record is first displayed, but only that one time.

    I have tried the Form Load event which displays it before the form displays, Form Activate eventwhich doesn't show it at all,  Form Current eventwhich shows it only when I change a record, and Form GotFocus eventwhich doesn't show it at all.

    I know I could display this in a header or footer, but many of the forms I want to use this in are too busy for that.

    Suggestions welcome.

    Marj Weir

    Monday, January 11, 2016 7:20 AM

Answers

  • After re-reading your post it sounds like you want a popup message to show but only the first time a record has ever been displayed.

    In this case you would still need the code in two events, (1) On Load & (2) On Current
    You will need to have a field in the Table to store a value in each Record like 0/-1. You could name it FirstView, set the default value to -1.
    Add a bound control to the field above on the Form named "ckbFirstView" (without the quotes) and set the visible property to NO

    Your code would be something like,

    Option Compare Database
    Option Explicit

    Private Sub Form_Current()
       Dim StrMsg As String
       Dim iResponse As Integer

    If Me.ckbFirstView = -1 Then

        StrMsg = "Place some text here" & Chr(10)
        StrMsg = StrMsg & "Place more text here" & Chr(10)
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & "Select: Cancel to place some text here" & Chr(10)
        StrMsg = StrMsg & "Select: OK to place some text here"
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & Chr(10) & "place some text here"

        iResponse = MsgBox(StrMsg, vbOKCancel, "place some text here")

    Select Case iResponse

    Case vbOK

    Beep
    'or tell your db to do something like change the value of FirstView

    Case vbCancel
    'Do what you told the would happen in the message box

    End Select

    Me.ckbFirstView = 0
    Else
    'Do Nothing
    End If
    End Sub


    Private Sub Form_Load()
       Dim StrMsg As String
       Dim iResponse As Integer

    If Me.ckbFirstView = -1 Then

        StrMsg = "Place some text here" & Chr(10)
        StrMsg = StrMsg & "Place more text here" & Chr(10)
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & "Select: Cancel to place some text here" & Chr(10)
        StrMsg = StrMsg & "Select: OK to place some text here"
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & Chr(10) & "place some text here"

        iResponse = MsgBox(StrMsg, vbOKCancel, "place some text here")

    Select Case iResponse

    Case vbOK

    Beep
    'or tell your db to do something like change the value of FirstView

    Case vbCancel
    'Do what you told the would happen in the message box

    End Select

    Me.ckbFirstView = 0
    Else
    'Do Nothing
    End If
    End Sub

    If you want to set all record values in the Table to -1 for first use then use an update query for the FirstView Field or for existing Records that you want to test this on you will need to manually update the FirstView Field to -1 for it to work as creating a field after the fact does not set the value to -1 for existing records.

    Please let us know if this is what you are looking for.


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    • Marked as answer by David_JunFeng Thursday, January 21, 2016 1:48 AM
    Thursday, January 14, 2016 4:10 PM

All replies

  • Hi Marj Weir,

    You have the answer in your question...

    Form Load event which displays it before the form displays

    and

    Form Current event which shows it when I change a record

    Hth


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Monday, January 11, 2016 10:51 PM
  • Hi Marj Weir,

    Can you elaborate on what you mean with "when a form record is first displayed"? If the form contains five records, do you want the message box to display each time you navigate to each record but only one time and not repeat if you navigate back to a previously displayed record?

    Monday, January 11, 2016 11:11 PM
  • >>>I want to display a simple MsgBox when a form record is first displayed, but only that one time.

    According to your description, if I don't misunderstand, you could open the form, then open the message box:

    DoCmd.OpenForm "FormName"
    MsgBox "Show your message box information"

    Tuesday, January 12, 2016 5:13 AM
  • After re-reading your post it sounds like you want a popup message to show but only the first time a record has ever been displayed.

    In this case you would still need the code in two events, (1) On Load & (2) On Current
    You will need to have a field in the Table to store a value in each Record like 0/-1. You could name it FirstView, set the default value to -1.
    Add a bound control to the field above on the Form named "ckbFirstView" (without the quotes) and set the visible property to NO

    Your code would be something like,

    Option Compare Database
    Option Explicit

    Private Sub Form_Current()
       Dim StrMsg As String
       Dim iResponse As Integer

    If Me.ckbFirstView = -1 Then

        StrMsg = "Place some text here" & Chr(10)
        StrMsg = StrMsg & "Place more text here" & Chr(10)
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & "Select: Cancel to place some text here" & Chr(10)
        StrMsg = StrMsg & "Select: OK to place some text here"
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & Chr(10) & "place some text here"

        iResponse = MsgBox(StrMsg, vbOKCancel, "place some text here")

    Select Case iResponse

    Case vbOK

    Beep
    'or tell your db to do something like change the value of FirstView

    Case vbCancel
    'Do what you told the would happen in the message box

    End Select

    Me.ckbFirstView = 0
    Else
    'Do Nothing
    End If
    End Sub


    Private Sub Form_Load()
       Dim StrMsg As String
       Dim iResponse As Integer

    If Me.ckbFirstView = -1 Then

        StrMsg = "Place some text here" & Chr(10)
        StrMsg = StrMsg & "Place more text here" & Chr(10)
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & "Select: Cancel to place some text here" & Chr(10)
        StrMsg = StrMsg & "Select: OK to place some text here"
        StrMsg = StrMsg & Chr(10)
        StrMsg = StrMsg & Chr(10) & "place some text here"

        iResponse = MsgBox(StrMsg, vbOKCancel, "place some text here")

    Select Case iResponse

    Case vbOK

    Beep
    'or tell your db to do something like change the value of FirstView

    Case vbCancel
    'Do what you told the would happen in the message box

    End Select

    Me.ckbFirstView = 0
    Else
    'Do Nothing
    End If
    End Sub

    If you want to set all record values in the Table to -1 for first use then use an update query for the FirstView Field or for existing Records that you want to test this on you will need to manually update the FirstView Field to -1 for it to work as creating a field after the fact does not set the value to -1 for existing records.

    Please let us know if this is what you are looking for.


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    • Marked as answer by David_JunFeng Thursday, January 21, 2016 1:48 AM
    Thursday, January 14, 2016 4:10 PM
  • Thanks.  I did something along the lines you describe, but I tested a counter for a value of zero in Surrent and then incremented it with each new Current record.  It didn't work my way but yours looks appealing.

    Thanks.

    Wednesday, January 27, 2016 4:41 AM