Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-25
8
Medium Priority
?
1,230 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

610 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