Solved

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

Posted on 2014-03-25
8
1,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

726 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