Results 1 to 6 of 6
  1. #1
    capjlp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Location
    Berea, Ky
    Posts
    26

    Turn on and off Visibility of a Image by record count query

    Hi Folks

    I have a current database that uses a form for registration at an event. We have a table with people that may register. When they come by we look them up then click a check box to register them for the event. We are having an event where we want to give away a prize to every 25th person that registers so we would like to have an image on the form become visible for every 25th registered person. all our data is pretty much in one table for this event. My thoughts were I could just use a count query for people in the registration table with a check mark on registered. Then do magic to make the image visible for every 25th person. We will give out the prize when they are registering so we want to see the image and give them their Prize. Seems like I would use an after update event on the Registered Check mark to update the state of the image.



    Thank you

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    at the SAVE button on click event

    Code:
      vCount = dcount("*","table")
      if (vCount mod 25) = 0 then 
         image.visible = true
         msgbox "Congrats"
     else
              image.visible = false
      endif

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In code, use a query to get the number of registered people. Then use the Mod function to determine if the 25th person.

    Air Code:
    Code:
    Private Sub Registered_AfterUpdate()
        Dim r As DAO.Recordset
        Dim RC As Long
    
        'always hide image
        Me.WinnerImage.Visible = False
    
        'get number of people regixtered
        sSQL = "SELECT Count(IsSelected) AS CountOfIsSelected FROM Table1 WHERE IsSelected = True;"
        Set r = CurrentDb.OpenRecordset(sSQL)
    
        'check if records
        If Not (r.BOF And r.EOF) Then
            RC = r.RecordCount
            If RC Mod 25 = 0 Then   '<- 25 th person
                Me.WinnerImage.Visible = True  'show
            Else
                Me.WinnerImage.Visible = False  ' hide
            End If
        End If
    
        'clean up
        r.Close
        Set r = Nothing
    
    End Sub
    Change the red names to your table, field and image names.

  4. #4
    capjlp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Location
    Berea, Ky
    Posts
    26
    I'll give this a try than you!

  5. #5
    capjlp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Location
    Berea, Ky
    Posts
    26
    Ok I tried this and can't seem to get it to work I set it to 5 people for testing. I tested the image true and false call on a on click and it does work but not after update on the 5th peoples. I set a label up to be = r.recordset and its always 1

    Private Sub chkRegistered_AfterUpdate()
    'Count Registered and Turn on WinnerImage
    Dim r As DAO.Recordset
    Dim RC As Long

    'always hide image
    Me.WinnerImage.Visible = False


    'get number of people regixtered
    sSQL = "SELECT Count([Registered]) AS [Total Registered] FROM CustomerTable WHERE (((CustomerTable.Registered)=True));"
    Set r = CurrentDb.OpenRecordset(sSQL)


    'check if records
    If Not (r.BOF And r.EOF) Then
    RC = r.RecordCount
    If RC Mod 5 = 0 Then '<- 5 th person
    Me.WinnerImage.Visible = True 'show
    Else
    Me.WinnerImage.Visible = False ' hide
    End If
    End If


    'clean up
    r.Close
    Set r = Nothing
    End Sub

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    My bad I was doing a lot of cutting and pasting and cut the wrong lines.
    Try this:
    Code:
    Option Compare Database   '<- should be the first line in every module
    Option Explicit           '<- should be the second line in every module
    
    Private Sub chkRegistered_AfterUpdate()
        'Count Registered and Turn on WinnerImage
        Dim r As DAO.Recordset
        Dim RC As Long
        Dim sSQL As String
    
        'always hide image
        Me.WinnerImage.Visible = False
    
        'save record
        Me.Dirty = False
    
        'get number of people registered
        sSQL = "SELECT Count([Registered]) AS TotalRegistered FROM CustomerTable WHERE CustomerTable.Registered = True;"
        Set r = CurrentDb.OpenRecordset(sSQL)
    
        'check count of records registered
        If Not (r.BOF And r.EOF) Then
            RC = r("TotalRegistered")
            If RC Mod 5 = 0 Then    '<- 5 th person
                Me.WinnerImage.Visible = True    'show
            Else
                Me.WinnerImage.Visible = False    ' hide
            End If
        End If
    
        'clean up
        r.Close
        Set r = Nothing
    End Sub
    Note: I removed the space in "TotalRegistered"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Query Record Count Error
    By dac214 in forum Programming
    Replies: 9
    Last Post: 03-07-2014, 03:36 PM
  2. count record in query
    By mikichi in forum Queries
    Replies: 1
    Last Post: 01-28-2014, 06:58 AM
  3. Totals Query Record Count with Criteria
    By rmoreno in forum Queries
    Replies: 3
    Last Post: 06-07-2013, 09:16 AM
  4. Replies: 3
    Last Post: 08-03-2012, 02:37 AM
  5. Turn Off Auto Save Record
    By Syntinal in forum Forms
    Replies: 2
    Last Post: 03-01-2009, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums