Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Unanswered: Including a random picture

    I produce a report (which obviously outputs the result of some queries). If there is no data, then a graphic is shown on the report - that's easy.

    I have a collection of ten other graphics, and I'd like to include one (chosen at random) in the report, if there is any data.

    My graphics are called Overdue0, Overdue1 ..... Overdue9.

    Any ideas?
    Thank you,
    James

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Re: Including a random picture

    Originally posted by jamesmc2
    I produce a report (which obviously outputs the result of some queries). If there is no data, then a graphic is shown on the report - that's easy.

    I have a collection of ten other graphics, and I'd like to include one (chosen at random) in the report, if there is any data.

    My graphics are called Overdue0, Overdue1 ..... Overdue9.

    Any ideas?
    Make a function to optain a random number:

    Function makeRandom(lowerLim As Integer, upperLim As Integer) As Single
        ' Calling makeRandom(0,9)
      &nbsp   &nbsp Randomize (Timer)
      &nbsp   &nbsp makeRandom = Int((Rnd * (upperLim - lowerLim)) + lowerLim)
    End Function


    In your Photo Source put
    Overdue&makeRandom(0,9)

    Hope it should function

  3. #3
    Join Date
    Feb 2004
    Location
    Swindon, UK
    Posts
    86

    Re: Including a random picture

    you could try the following

    Dim MyVal
    MyVal = Int((10 * Rnd) + 1) ' Generate random value between 1 and 10
    Me.Picture = "C:\Overdue" & MyVal & ".jpg"
    Last edited by Mowgli212001; 02-05-04 at 06:29.

  4. #4
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Re: Including a random picture

    Originally posted by Mowgli212001
    you could try the following

    Dim MyVal
    MyVal = Int((10 * Rnd) + 1) ' Generate random value between 1 and 10
    Me.Picture = "C:\Overdue" & MyVal & ".jpg"

    Hi, I wasn't sure where to use this....I assume in the Open Report event. My code looks like this. The pictures are now number Overdue_11 to Overdue_36 and the Picture object is called ImageToUse. The random number is generated ok, but I still get an error "Run Time error 2448 - You can't assign a value to this object."

    So I'm still stuck


    Private Sub Report_Open(Cancel As Integer)
    Dim MyVal
    MyVal = Int((36 * Rnd) + 11) ' Generate random value between 11 and 36
    Me.ImageToUse = "P:\aioc\ACG\KPI_TOYBOX\Overdue_" & MyVal & ".jpg"
    End Sub
    Thank you,
    James

  5. #5
    Join Date
    Feb 2004
    Location
    Swindon, UK
    Posts
    86
    sorry about that James. forgot to add the Picture Property. Try this

    Private Sub Report_Open(Cancel As Integer)
    Dim MyVal
    MyVal = Int((36 * Rnd) + 11) ' Generate random value between 11 and 36
    Me.ImageToUse.Picture = "P:\aioc\ACG\KPI_TOYBOX\Overdue_" & MyVal & ".jpg"
    End Sub

    This will work in the either of the following

    Private Sub Report_Open(Cancel As Integer)
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Last edited by Mowgli212001; 02-05-04 at 07:48.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •