Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

OnTimer event coding

Posted on 2003-11-18
17
Medium Priority
?
749 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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
 
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 500 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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