VBA Loop zooming picture

In this example, you will learn VBA For... Next Loop and If Else Conditional Statement to change the size of picture(zooming picture in) according to the timer. The example illustrates ZoomingPicture form like the figure below:

 VBA example - Microsoft Access VBA Zooming Form 

When the form loads (in full screen) and the timer runs, the picture automatically zooms in( bigger and bigger). It will stop to zoom in at the limited value defined by code.

To have a form as the figure above, you must have a picture and create the form in Form Design. See as the figure below:

VBA example - Microsoft Access VBA Zooming Form Design 

- Drag and drop an image control on a form.

Then apply the VBA Code below:


Option Compare Database

Option Explicit

Dim j As Integer


Private Sub Form_Load()

DoCmd.Maximize        ' Show form in full screen

Image0.Picture = CurrentProject.Path & "\Sphere.png"    ' Display picture

Image0.Left = -2500 + WindowWidth / 2    ' Set starting position of the picture

Image0.Top = -3000 + WindowHeight / 2

TimerInterval = 1000 'Set time interval

j = 1      ' Start value of counter j

End Sub


Private Sub Form_Timer()

Dim w, h, t, l As Long

Dim i As Long

'Delay in changing size of picture

For i = 1 To 10



If j < 40 Then    ' Stop zooming when j is greater than  or equal to 40

        w = Image0.Width    ' Get current picture size

        h = Image0.Height

        t = Image0.Top

        l = Image0.Left

        Image0.Width = w + 100      ' Change picture size to bigger

        Image0.Height = h + 100

        j = j + 1

End If

End Sub

HTML Comment Box is loading comments...

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.