Solved

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

Posted on 2014-03-25
8
998 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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:MurphyPH
Comment Utility
I have a 64-bit version of MS Office with Access.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now