Solved

OnTimer event coding

Posted on 2003-11-18
17
728 Views
Last Modified: 2009-07-29
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?
0
Comment
Question by:cpopham
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9772802
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
 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9772858
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
 

Author Comment

by:cpopham
ID: 9772873
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
 

Author Comment

by:cpopham
ID: 9772912
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
 
LVL 32

Expert Comment

by:jadedata
ID: 9772965
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
 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9773047
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
 

Author Comment

by:cpopham
ID: 9773147
Nothing is visible when I put that code in Jack.  This is what I have so far:
0
 

Author Comment

by:cpopham
ID: 9773206
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 1

Expert Comment

by:Jagdish_Bodani
ID: 9773247
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
 

Author Comment

by:cpopham
ID: 9773370
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
 

Author Comment

by:cpopham
ID: 9773396
JagDish,
I am also getting a compile error on the End Sub:

Select Case without end select..
0
 

Expert Comment

by:stawicki
ID: 9774335
no, half a second is 500!  The time is in milliseconds  - thats 1000 per second!
0
 

Author Comment

by:cpopham
ID: 9775869
I know it is in milliseconds.  I was saying I just wanted them very brief like half a second.  Anyone have any ideas?
0
 
LVL 1

Expert Comment

by:ErnestMcDuff
ID: 9778342
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
 
LVL 1

Accepted Solution

by:
Jagdish_Bodani earned 125 total points
ID: 9779554
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
 

Author Comment

by:cpopham
ID: 9782706
I will try that upon my return to work or perhaps tonight.  We got hit with the heavy rains.
0
 

Author Comment

by:cpopham
ID: 9787397
That works great and does exactly what I need it to do.  Thanks for the help!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

760 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

21 Experts available now in Live!

Get 1:1 Help Now