Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Run Slide Show when Form is Idle

Dear Readers,

I am very sorry about last two weeks unexpected events and could not come out with the weekly Articles. I had to go to India on an emergency on 27th September 2009 and the Website also failed on the same day itself due to some errors in the Web Server Configuration changes made by Administrators.

I have noticed this serious state of the Website on 8th of October and could bring up the Site only on 9th of October 2009. I deeply regret the inconvenience caused to you.


This week, we will create a Slide Show of images on a Form that runs when the Form remains idle for a certain period of time. It works something like the following:

  • When the Main Switchboard Form remains idle for about one minute the Slide Show runs and each image will change on a fixed interval of about 6 Seconds. The Idle Time and Interval Time can be changed according to your specific needs.
  • The idle time of the Form is calculated based on the inactivity (i.e. no interaction with the User) of the Main Switchboard Form and the active control on the Form remains active for more than one minute.
  • If you click on a Command Button or List box or any other control other than the active control on the Main Switchboard Form then the Form comes out of idle state and the Slide Show stops.
  • Checking for the idle state of the Form starts again from that point onwards with the new active control. If the same control remains active for more than one minute then the slide show starts again.
  • If you open another Form over the Main Switchboard Form then the slide show sleeps until the Main Switchboard From becomes active again.
  • You need few Bitmap Images of Landscapes or Photos and you can use as many images as you like for the Slide Show. All the images should have the same name with a Sequence Number at the end like Image1.bmp, Image2.bmp, Image3.bmp and so on. You can use .jpg or .GIF and other images but this will display a progress bar for a brief moment while loading the image into the Image Control. All images must be of the same type.

Sample Main Switchboard Form

A sample Main Switchboard Form with the active Slide Show is given below:

Click to Enlarge

The Design Task

  1. To try out this interesting trick; first organize few Bitmap Images into a folder as explained above.
  2. Make a copy of your existing Main Switchboard Form (Control Screen).
  3. Open the Form in Design View.
  4. Make enough room on the Form to create an Image Control on the Form.
  5. Display the Toolbox (View - - >Toolbox), if it is not visible.
  6. Select Control Wizards button on the Toolbox to make it active.
  7. Select Image control Tool from the Toolbox and draw an Image Control on the Form where you want the Slide Show to appear.
  8. The Common Dialog Control will display. Browse to the Images location and select the image with Serial Number 1 (Image1.bmp).

    The selected image will appear in the Image Control.

  9. While the Image control is still in selected state; display the Property Sheet (View - -> Properties) and change the following Property Values as indicated below:
    • Name = ImageFrame
    • Size Mode = Zoom

    NB: We need part of the Picture Property Value (the location address of the Images) to make changes in the Program that we are going to introduce into the Code Module of the Form. So, note down the image location address on paper from the Picture Property or copy and paste it into a Notepad Document for later use.

  10. Display the Code Module of the Form (View - -> Code).
  11. Press Ctrl+A to highlight the existing VBA Code in the Module, if present, and press Delete to remove them.
  12. Copy and Paste the following Code into the Form Module.

    SwitchBoard Form Module VBA Code

    Option Compare Database
    Option Explicit
    Dim actForm As String, actControl As String, idletime As Integer
    Dim oldForm As String, oldControl As String, imageNo As Integer
    Private Sub Form_Activate()
        Me.TimerInterval = 1000
    End Sub
    Private Sub Form_Deactivate()
        Me.TimerInterval = 0
        Me.ImageFrame.Visible = False
    End Sub
    Private Sub Form_Load()
    idletime = 0
    Me.ImageFrame.Visible = False
    Me.TimerInterval = 1000
    End Sub
    Private Sub Form_Timer()
    actForm = Screen.activeForm.Name
    actControl = Screen.activeForm.activeControl.Name
    If actForm = oldForm And actControl = oldControl And actForm = "Control" Then
        idletime = idletime + 1
        oldForm = actForm
        oldControl = actControl
        idletime = 0
        Me.ImageFrame.Visible = False
    End If
    If idletime > 60 Then
       If idletime Mod 6 = 0 Then
            Me.ImageFrame.Visible = True
            imageNo = imageNo + 1
     imageNo = IIf(imageNo < 1 Or imageNo > 9, 1, imageNo)
     Me.ImageFrame.Picture = "E:\D\Movie\Britanica_Scenes\scene" & imageNo & ".bmp"
       End If
    End If
    End Sub

    Make Important Changes to References

    You have to make changes on few lines in the program that appears in bold letters.

  13. Change the word "Control" in the first line (with bold letters) with your own Main Switchboard Form Name.
  14. Change Number 9, in the second line with bold letters, to match with the number of Images you have saved for the Slide Show as explained above.
  15. Copy the Image Location Address and Image Name except Serial Number from the image location address we have saved in Notepad Document and Paste over the text E:\D\Movie\Britanica_Scenes\scene in the Program.
  16. If your pictures are not Bitmap Images then change the file extension ".bmp" to indicate your image type.
  17. Save and Close the Form.
  18. Open the Main Switchboard Form in Normal View.
  19. Wait for one minute to begin the Slide Show.

Interupting the Slide Show.

When the Slide Show is running, if you click on a Control other than the active control on the Form the Slide Show will stop and the image will disappear.

If you don't click on any other control on the Form and the time elapsed is more than one minute, since your last click on a Control, the Slide Show will run again.

If you want to increase or decrease the idle time of the Form then change the value in the VBA line If idletime > 60 Then to an appropriate value you prefer.

Each Image stays displayed for about 6 seconds. If you want to increase or decrease the display time then change the Value in the VBA line

If idletime Mod 6 = 0 Then to the required value you prefer.


1 comment:

  1. [...] number with .jpg file extension like: 12345.jpg. Learn another trick with pictures from this link: Run Slide Show when the Form is idle __________________ http://www.msaccesstips.com (Learn MS-Access Tips and Tricks) Learn Advanced [...]


Comments are subject to moderation before publishing.


Subscribe in a reader
Your email address:

Delivered by FeedBurner

Blog Directory Visit blogadda.com to discover Indian blogs


Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email


Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Class Module Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Array Queries msaccess reports External Links msaccess tips Accesstips Downloads Objects Property Menus and Toolbars Controls Event MsaccessLinks Process Controls Art Work Collection Object WithEvents msaccess How Tos Combo Boxes Graph Charts List Boxes VBA msaccessQuery Command Buttons Command Button Data Dictionary Object Emails and Alerts Form Query RaiseEvent Report Calculation Custom Wizards DOS Commands Data Type ms-access functions msaccess functions msaccess graphs msaccess reporttricks Custom Functions Item Object Reference msaccessprocess security advanced Access Security Add Field Type Fields Form Instances Key Macros Menus SubForm Top Values Variables msaccess email msaccess menus progressmeter Access2007 Auto-Number Copy Excel Expression Join Methods Microsoft Numbering System Records Recordset Security Split Table Time Difference Utility Workgroup Wrapper Classes database function ms-access msaccess wizards reference text tutorial vba code Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif msaccess msaccess alerts pdf files restore switch toolbar updating upload

Featured Post

ROUNDDOWN Function of Excel

We have introduced ROUNDUP() Function of Excel in Microsoft Access earlier.  It works like ROUND() Function except that the number is alway...


Blog Archive

Recent Posts