Results 1 to 12 of 12
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MsgBox (A2000 SR1)

    In some instances of my DB, when a user saves a record, I have a pop-up msgbox that states "Record Saved"

    I use the line. MsgBox "Record Saved"

    What I would like is the Message to pop-up but without the OK button.
    Ideally when a user saves a record, the message pops up and closes automatically after a second or so.
    Is this possible without creating a separate form with an on timer event ???

    Dave

  2. #2
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Wellington, New Zealand
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    I know that it isn't an answer to your problem entirely...but I wonder if you could use standard message box (with OK button), then use the 'sendkeys' command to send a carriage return to the msgbox? Don't know if that would work.

    I would say that it is easier to create a seperate form than do this though. You could create a seperate 'generic' form for this purpose, passing whatever message you want displayed in the 'openargs' argument for the form. This means that you could have the one form for many purposes. Just an idea.

    Cheers

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    Thanks for reply Jayden.

    I have looked at using a custom form, which I must say worked for some occasions.
    The problem here is working with nested forms.
    When teh form closes, it doesn't always set to the correct focus, which I really wanted to go down the msgbox route.

    Thanks any way.

    Dave

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox (A2000 SR1)

    The DoCmd.Close statement is dangerous in its short form. Instead, use it like this:

    DoCmd.Close acForm, Me.Name

    That will always close the form in which the code is run and can be copied and pasted into any form without changes.
    Charlotte

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: MsgBox (A2000 SR1)

    Another thought is to use Echo to put the message in the status bar. Then you could hide it again after a set time.
    It is not as obvious to the users though.
    Regards
    John



  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    Thanks for the info Charlotte, I will be editing later to remedy some of my close statements.

    John, the echo scenario looks promising.
    Do you have an example on how I should implement this.

    Thanks all

    dave

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    I found the following browsing different sites.
    Would anyone mind helping me to use it.
    Where to put it, & implement it.

    Thanks in haste
    Dave
    Option Compare Database

    '************* Code Start **************
    ' Display a simple popup message dialog for a given number of
    ' seconds.
    '
    ' This code was written by Michael Bedward
    ' mbedward@ozemail.com.au
    ' March 31, 1999.
    '
    ' You are free to distribute and use this code as you wish
    ' but it would be nice if you credit the original author
    ' (by leaving this notice intact). Improvements will be
    ' gratefully accepted.
    '
    ' Modifications:
    ' April 12, 1999
    ' Added modifications suggested by Mark West (mrwest@engin.umich.edu):
    ' code to auto-size form according to label size;
    ' optional args to set font name and size;
    ' code to delete form object.
    '
    ' April 16,1999
    ' Added error handler as suggested by Dev Ashish (dash10@hotmail.com).
    '
    Sub mxbPopupMessage(ByVal message As String, _
    Optional ByVal Title As Variant, _
    Optional ByVal duration As Single, _
    Optional strFontName As String, _
    Optional intFontSize As Integer)
    Dim f As Form
    Dim lbl As Label
    Dim dblWidth As Double
    Dim myName As String
    Dim savedForm As Boolean

    ' used for error handling
    '
    savedForm = False

    ' turn off screen repainting so that we don't see the
    ' form being created
    '
    On Error GoTo ErrorHandler
    Application.Echo False

    ' make a simple blank form
    '
    Set f = CreateForm
    myName = f.Name
    f.RecordSelectors = False
    f.NavigationButtons = False
    f.DividingLines = False
    f.ScrollBars = 0 ' none
    f.PopUp = True
    f.BorderStyle = acDialog
    f.Modal = True
    f.ControlBox = False
    f.AutoResize = True
    f.AutoCenter = True

    ' set the title
    '
    If IsMissing(Title) Then
    f.Caption = "Info"
    Else
    f.Caption = Title
    End If

    ' add a label for the message
    '
    Set lbl = CreateControl(f.Name, acLabel)
    lbl.Caption = message
    lbl.BackColor = 0 ' transparent
    lbl.ForeColor = 0
    lbl.Left = 100
    lbl.Top = 100
    If strFontName <> "" Then lbl.FontName = strFontName
    If intFontSize > 0 Then lbl.FontSize = intFontSize
    lbl.SizeToFit
    dblWidth = lbl.Width + 200
    f.Width = dblWidth - 200
    f.Section(acDetail).Height = lbl.Height + 200

    ' display the form (first close and save it so that when
    ' it is reopened it will auto-centre itself)
    '
    DoCmd.Close acForm, myName, acSaveYes
    savedForm = True
    DoCmd.OpenForm myName
    DoCmd.MoveSize , , dblWidth
    DoCmd.RepaintObject acForm, myName

    ' turn screen repainting back on again
    '
    Application.Echo True

    ' display form for specifed number of seconds
    '
    If duration <= 0 Then duration = 2
    Dim startTime As Single
    startTime = Timer
    While Timer < startTime + duration
    Wend

    ' close and delete the form
    '
    DoCmd.Close acForm, myName, acSaveNo
    DoCmd.DeleteObject acForm, myName
    Exit Sub

    ErrorHandler:
    Application.Echo True
    Dim i As Integer
    For Each f In Forms
    If f.Name = myName Then
    DoCmd.Close acForm, myName, acSaveNo
    Exit For
    End If
    Next f
    If savedForm Then
    DoCmd.DeleteObject acForm, myName
    End If

    End Sub

  8. #8
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Wellington, New Zealand
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    If you were to use a 'custom form', I would open it as a dialog form using the docmd statement (it is one of the options), look it up in help. This should solve the problem of losing the focus for the appropriate control on the originating form (if it doesn't, you can very specifically set the focus to the appropriate control in the line after the docmd (the code in the main form halts if you open a form as a dialog form until that form is closed).

    Jayden

  9. #9
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: MsgBox (A2000 SR1)

    Dave try this

    Dim lngi As Long
    Dim j As Integer
    DoCmd.Beep
    DoCmd.Echo False, "Record deleted"
    For lngi = 1 To 10000000
    j = 5
    Next lngi
    DoCmd.Echo True

    The loop in the middle is just to cause a delay until the message goes away. I know there is a simpler way to do this, but I can't remember what it is.
    Regards
    John



  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox (A2000 SR1)

    Put it in a standard module and name the module anything except mxbPopupMessage. CAll it like this:

    <pre>Call mxbPopupMessage(message:="This is the message", Title:="Form Caption", _
    duration:=5, strFontName:="Arial, intFontSize:=10)</pre>


    You should see the message "This is the message" on a form with "Form Caption" in the form title bar, and it should appear for 5 clockticks and then the form should close. It isn't actually necessary to set the font name or size, and you'll get a default caption of "Info" if you don't pass in the caption argument.
    Charlotte

  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox (A2000 SR1)

    Charlotte.
    I was getting syntax error, expected list or separator ?
    Sorted Thanks


    Dave

  12. #12
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: MsgBox (A2000 SR1)

    If you call sub with arguments in parentheses without "Call" statement you will get the "Expected list or separator" error. To call sub without "Call" use this syntax:
    <pre>mxbPopupMessage message:="This is the message", Title:="Form Caption", _
    duration:=5, strFontName:="Arial, intFontSize:=10</pre>

    From Help file:
    <hr>You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist.<hr>

    HTH

Posting Permissions

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