Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Run Slide Show when Form is Idle

Introduction

This week, we’ll create a slide show of images that automatically run on a Form whenever it remains idle for a specified period of time.

Here’s how it works:

When the Main Switchboard Form remains idle for one minute, the slide show begins, cycling through a series of images at fixed intervals—typically every six seconds. Both the idle time and interval duration can be customized to suit your needs.

The Form’s idle time is determined by monitoring user activity. If no interaction occurs (that is, the same control on the Form remains active for over one minute), the slide show starts automatically.

Once the user interacts with the Form—by clicking a command button, list box, or any control other than the active one—the Form exits its idle state, and the slide show stops. The system then resets its idle-time counter, resuming monitoring for inactivity from that point onward.

If another Form is opened over the Main Switchboard, the slide show pauses automatically and resumes only when the Switchboard becomes active again.

To set up the slide show, you’ll need several bitmap images (landscapes, photos, etc.). You can use as many as you like, but all must follow a consistent naming pattern, such as:

1.bmp, 2.bmp, 3.bmp, and so on.

Other image formats, such as JPG, GIF, or PNG, are also supported, though you may briefly see a progress bar as each image loads into the Image control. For best results, ensure that all images are of the same type and dimensions.

Sample Main Switchboard Form

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


The Design Task

  1. To try out this interesting trick, first, organize a 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 the Control Wizards button on the Toolbox.

  7. Select the Image control Tool from the Toolbox and draw an Image Control on the Form where you want the SlideShow to appear.

  8. The Common Dialog Control will display. Browse to the Image location and select the image with Serial Number 1 (Image1.bmp).

    The selected image will appear in Image Control.

  9. While the Image control is still in the selected state, display the Property Sheet (View -> Properties) and change the following Property Values as indicated below:

    • Name = ImageFrame

    • Size Mode = Zoom

    Note: Before proceeding, we’ll need part of the Picture property value — specifically, the file path where your images are stored. This path will be used in the VBA code we’re about to add to the Form’s module.

    Open the Form in Design View, select the Image Control, and check its Picture property in the Property Sheet. Note down the image file location (for example, C:\MyDatabase\Images\1.bmp), or copy and paste it into a Notepad document for future reference.

  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 it.

  12. Copy and Paste the following Code into the Form Module.

    Switchboard Form Module VBA Code (Revised Code)

    Option Compare Database
    
    Dim actForm As String, actControl As String, idletime As Integer
    Dim oldForm As String, oldControl As String, imageNo As Integer
    Dim s_path As String
    
    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()
    DoCmd.Restore
    idletime = 0
    imageNo = 0
    s_path = CurrentProject.Path
    Me.ImageFrame.Visible = False
    Me.TimerInterval = 1000
    End Sub
    
    Private Sub Form_Timer()
    Dim txt As String
    
    txt = "Slide-Show Starts In: "
    
    actForm = Screen.ActiveForm.Name
    actControl = Screen.ActiveForm.ActiveControl.Name
    
    If actForm = oldForm And actControl = oldControl And actForm = "SlideShow" Then
        idletime = idletime + 1
        
        If idletime > 15 And idletime < 31 Then
            
          Me.Lblup.Visible = True
          Me.Lblup.caption = txt & (30 - idletime) & " Seconds."
            
        Else
            Me.Lblup.Visible = False
        End If
    Else
        oldForm = actForm
        oldControl = actControl
        idletime = 0
        Me.ImageFrame.Visible = False
        Me.Employees.Visible = False
        DoEvents
    End If
    
    If idletime > 30 Then
        Me.Lblup.Visible = False
        DoEvents
       If idletime Mod 5 = 1 Then
            Me.ImageFrame.Visible = True
            Me.Employees.Visible = True
            imageNo = imageNo + 1
            imageNo = IIf(imageNo < 1 Or imageNo > 9, 1, imageNo)
            Me.ImageFrame.Picture = s_path & "\" & imageNo & ".bmp"
            
            DoEvents
       End If
    End If
    
    End Sub
    
    

    Make Important Changes to References

  13. Change the "SlideShow" reference in the VBA code line with your own Main Switchboard Form Name.

  14. Change Number 9, in the second line with bold letters, to match the number of Images you have saved for the Slide Show as explained above.

  15. If your pictures are not Bitmap Images, then change the file extension ".bmp" to indicate your image type.

  16. Save and Close the Form.

  17. Open the Main Switchboard Form in Normal View.

  18. Wait for one minute to begin the Slide Show.

Interrupting 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 30 seconds 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 idle time > 30 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

The idle time Mod 5 = 1, change it to the required time delay between two slides for viewing.

Download the Demo Database from the Link given below:

NOTE: Unzip the Database with Photos into a Temporary Folder and open the Database from there. Read the Notes given in the Form for details on how it runs and how to disable it, etc.

Share:

3 comments:

  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 [...]

    ReplyDelete
  2. Hi sir.
    I follow you on Facebook please I want to ask if you can make a video tutorial on it thank you

    ReplyDelete
    Replies
    1. Hello, I am sorry I could not reply to you so far. I have attached a Demo Database at the end of this Article. The database and the sample images are in the zipped file. Create a Temporary folder on your Disk Drive, unzip the files and save them in the new folder. Open the database from there. Read the information given in the Form. The Slide-Show will start after 30 seconds after opening the Form.

      Delete

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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