OnTimer event coding

I would like to have images appear and disappear one after the other on the Time Interval set on my form.  This is my code so far, but I can not get the OnTimer code to compile correctly:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
   Me.Image0.Visible = True
   Me.Image0.Visible = False
   Me.OnTimer.Image1.Visible = True
 
   
End Sub

Any help please?
cpophamAsked:
Who is Participating?
 
Jagdish_BodaniCommented:
Hi,

Given below is complete code.  I have tested it and it works perfect.

Create as many images as you want on form.  Make them invisbile in design mode.
Make sure that you key desired time interval.

Code is under:

Option Compare Database
Option Explicit

'variable declared in general section outside procedure

Dim imagenumber As Integer



Private Sub Form_Load()
imagenumber = 1
End Sub


Private Sub Form_Timer()


Select Case imagenumber
    Case 1
          Me.Image1.Visible = True
          Me.Image3.Visible = False
    Case 2
          Me.Image2.Visible = True
          Me.Image1.Visible = False
    Case 3
          Me.Image3.Visible = True
          Me.Image2.Visible = False
End Select

If imagenumber <= 3 Then
    imagenumber = imagenumber + 1
Else
imagenumber = 1
End If

End Sub
0
 
jadedataMS Access Systems CreatorCommented:
Hey cpopham!

 Code for that type operation needs to be in the OnTimer event of the form.

  Private Sub Form_Timer
    ...
    your code here
    ...
  End Sub

This line:
  Me.OnTimer.Image1.Visible = True
is what the compiler doesn't like.

Explain further what exactly you want these image controls to do?

 


regards
Jack
0
 
Jagdish_BodaniCommented:
Hi,

On Form Property (Click on Left Top Box of the Form to Select Form and then Click on Property Icon or View/Properties), key Time Interval in Milliseconds.  Then on Timer Event of form type following code:

Private Sub Form_Timer()
if me.Image.Visible = True then
me.Image.Visible=False
else
me.image.visible=true
end if
End Sub
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
cpophamAuthor Commented:
Jack,
I am just wanting a series of images to appear one after the other.  So if I coded like this:

Private Sub Form_Timer
   Me.Image0.Visible = True
   Me.Image0.Visible = False
   Me.Image1.Visible = True
 
End Sub

Would it work on the time interval?  Or do I need to add to something to the code so that it will process certain parts of the code at the desired interval?
0
 
cpophamAuthor Commented:
The series is about 8 images long also...  So I would want it to loop back to the first image after until they clicked to go somewhere else...
0
 
jadedataMS Access Systems CreatorCommented:
Private Sub Form_Timer

  static ImgNum as Byte
   imgnum = imgnum + 1
   if imgnum>8 then imgnum = 0

   Me.Image0.Visible = (ImgNum = 0)
   Me.Image1.Visible = (ImgNum = 1)
   Me.Image2.Visible = (ImgNum = 2)
   Me.Image3.Visible = (ImgNum = 3)
   Me.Image4.Visible = (ImgNum = 4)
   Me.Image5.Visible = (ImgNum = 5)
   Me.Image6.Visible = (ImgNum = 6)
   Me.Image7.Visible = (ImgNum = 7)
   Me.Image8.Visible = (ImgNum = 8)
 
End Sub

Add error trapping and it's something like that...

0
 
Jagdish_BodaniCommented:
Hi again,

If you want to display 8 images in series, name all images in series like Image1, Image2...... Image8.

Make all Images Invisible in Design.  Visible=No

Dim ImageNumber as Integer

ImageNumber=1

Private Sub Form_Timer

Select Case ImageNumber
    case 1
          me.Image1.visible=True
    case 2
          me.image2.visible=ture

so on upto 8

If Imagenumber <=8 then
    ImageNumber=ImageNumber+1
else
ImageNumber=1
end if
End sub
 
0
 
cpophamAuthor Commented:
Nothing is visible when I put that code in Jack.  This is what I have so far:
0
 
cpophamAuthor Commented:
JagDish,

I tried it the way you mentioned and nothing is visible.  I also coded it this way and none of the images are visible:

Private Sub Form_Timer()

Dim ImageNumber As Integer

ImageNumber = 1

Private Sub Form_Timer()

Select Case ImageNumber
    Case 1
          Me.Image0.Visible = True
          Me.Image7.Visible = False
    Case 2
          Me.Image1.Visible = True
          Me.Image0.Visible = False
    Case 3
          Me.Image2.Visible = True
          Me.Image1.Visible = False
    Case 4
          Me.Image3.Visible = True
          Me.Image2.Visible = False
    Case 5
          Me.Image4.Visible = True
          Me.Image3.Visible = False
    Case 6
          Me.Image5.Visible = True
          Me.Image4.Visible = False
    Case 7
          Me.Image6.Visible = True
          Me.Image5.Visible = False
    Case 8
          Me.Image7.Visible = True
          Me.Image6.Visible = False
         
If ImageNumber <= 8 Then
    ImageNumber = ImageNumber + 1
Else
ImageNumber = 1
End If
End Sub
 

0
 
Jagdish_BodaniCommented:
Hi,

have you changed the Time Interval Property of Form.  You Must put TimeInterval in Milliseconds.  Don't Try very small number.  Try say at least 10000

0
 
cpophamAuthor Commented:
I wanted it to flash kind of fast.  I set it to .5 which should be .5 sec I will extend the time interval and try it.. Nope still nothing.
0
 
cpophamAuthor Commented:
JagDish,
I am also getting a compile error on the End Sub:

Select Case without end select..
0
 
stawickiCommented:
no, half a second is 500!  The time is in milliseconds  - thats 1000 per second!
0
 
cpophamAuthor Commented:
I know it is in milliseconds.  I was saying I just wanted them very brief like half a second.  Anyone have any ideas?
0
 
ErnestMcDuffCommented:
One of those days you find a nice question to bite your teeth into....

Dear cpopham,

I got it working and this is how I did it:

1) Put into a empty module (the image array has to be initialize public (see ps)) the next lines:

Option Compare Database
Option Explicit
Public arImage(1 To 8) As String
Public nrImage As Integer


2) Put into the Form_Open() prcodeure the next lines

    nrImage = 1
    arImage(1) = "C:\windows\Blue Lace 16.bmp"
    arImage(2) = "C:\windows\Coffee Bean.bmp"
    arImage(3) = "C:\windows\Feathertexture.bmp"
    arImage(4) = "C:\windows\Gone Fishing.bmp"
    arImage(5) = "C:\windows\Greenstone.bmp"
    arImage(6) = "C:\windows\Prairie Wind.bmp"
    arImage(7) = "C:\windows\Rhododendron.bmp"
    arImage(8) = "C:\windows\River Sumida.bmp"

3) Furthermore, put into your form_timer routine the following:

    Me.Image0.Picture = arImage(nrImage)
    nrImage = IIf(nrImage > 7, 1, nrImage + 1)

Please remove any other image you have available now. My little routine just replaces the source for the picture.
As you can see I've used some standard pics which, ofcourse you can change to whatever you want.

Hope you like it..
Ernest McDuff

PS If someone can tell how I can declare a variable public in the form's themselves, please let me know.
Not bad for an Access-newbee....
0
 
cpophamAuthor Commented:
I will try that upon my return to work or perhaps tonight.  We got hit with the heavy rains.
0
 
cpophamAuthor Commented:
That works great and does exactly what I need it to do.  Thanks for the help!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.