Solved

in ACCESS VBA how to create a popup message that just closes after one second.

Posted on 2014-03-25
8
1,044 Views
Last Modified: 2014-03-25
I need to have an after update event that opens a popup message that just fades away after a second or two without the need to click a button in the control.

All the msgbox items need to have a click response to close the popup.
0
Comment
Question by:MurphyPH
  • 5
  • 3
8 Comments
 
LVL 40
ID: 39953800
A message box is a modal form, which means that it blocks your code when you call it. So there is no way to do what you want with a message box.

You need to create a simple form with the single purpose of displaying your message.

And  since VBA does not have a built-in sleep function or timer as some other environments, you will need to call the Windows API Sleep command.

To do that, add the following in the declarations of your Form:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Open your form

Call Sleep(2000) is you want 2 seconds

Close your form
0
 

Author Comment

by:MurphyPH
ID: 39954050
I am not certain where I put:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

I tried to put it in the on-load event but it was highlighted as invalid.

Private Sub Form_Load()
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) <<this was highlighted in red as invalid.

End Sub
0
 

Author Comment

by:MurphyPH
ID: 39954136
Here is what got accepted in the main form as far as declarations goes:
Option Compare Database
Option Explicit
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

I put this in the declarations of the form that holds the message:
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

And this is the code that is in the after update on the main form:

Private Sub cbxSoilMat1_AfterUpdate()
If Me.SoilMatPct1 < 100 Then
Parent.Page3SoilSubform.Form.frmRedoxMessage.Visible = True
Call Sleep(2000)
Parent.Page3SoilSubform.Form.frmRedoxMessage.Visible = False
End If
End Sub

The message form does not show up.

If I leave out the lines:
Call Sleep(2000)
Parent.Page3SoilSubform.Form.frmRedoxMessage.Visible = False

The message form does show up.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:MurphyPH
ID: 39954146
I have a 64-bit version of MS Office with Access.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39954229
Sorry, it's been a while since I have programmed in Access, and I forget the little détails.

Add a DoEvents before the Sleep. This should leave time for your frmRedoxMessage form to draw itself on the screen before going to Sleep.

Parent.Page3SoilSubform.Form.frmRedoxMessage.Visible = True
DoEvents
Call Sleep(2000)
Parent.Page3SoilSubform.Form.frmRedoxMessage.Visible = False
0
 

Author Comment

by:MurphyPH
ID: 39954248
That worked.  I was investigating an alternative way to do the same thing.  What about a form timer.
I set the form timer to 2000, but I don't know how to close the form with the on-timer event.

Any ideas on that?
I will assign the points to you now.
0
 

Author Closing Comment

by:MurphyPH
ID: 39954249
Thanks.
0
 
LVL 40
ID: 39954286
I would stay with the Sleep if it works.

For the form timer, if memory is good, you set the form TimerInterval in milliseconds, same as for Sleep.

There is an event triggered when the delay expires. You hide your message in there with the same code that you used before if the event is in the same form as the one you used to display your message.

You should remember to reset the TimerInterval at 0 however because as I remember it, the timer in Access repeats itself if you do not stop it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question