Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Posts
    23

    Database Counter

    Hey everyone. I am trying to add a feature to my database that counts the number of times that the main menu is opened (I modified this form to always stay open in the background in order to get an accurate count) just out of curiosity.

    Right now I have a table called "Count Table" with a field called "Counter" on it. This table acts as the control source on my main menu. The main menu also has a text box called "Page Counter". The "On Open" code looks as follows:

    [Page Counter] = [Counter] + 1


    'This line seems to work, page counter displays 1 with counter set at 0
    [Counter] = [Page Count]
    'This is where I run into trouble. The database does not want to overwrite the Counter value in the Count Table.

    Any ideas of another way to do this? I tried doing a similar setup as shown above using the Dmax function but had the same outcome.

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    set a variable to [Counter] + 1 then run an update query to change the value

  3. #3
    Join Date
    Aug 2010
    Posts
    23
    Sorry for the late reply.

    I tried to play around with an update query but I guess im still a bit confused.

    How would I go about running the update query each time the page is loaded?

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Dim intCounter as Integer
    Dim strSQL as String

    intCounter = [Counter] + 1
    [Page Counter] = intCounter
    strSQL = "UPDATE tblName SET fldName = " & intCounter & ";"
    DoCmd.RunSQL (StrSQL)
    Me.controlNameOfCounter.Requery

    Throw that into your onOpen. I didn't check it but it should work.

  5. #5
    Join Date
    Aug 2010
    Posts
    23
    Awesome, that works perfect. Thanks a lot Shabz

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Give it a couple form closes and opens and make sure it still works. I have a slight concern that the way I have it set up may not get it right continuously.

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

Similar Threads

  1. ID Counter Problem
    By slash23 in forum Access
    Replies: 2
    Last Post: 07-06-2011, 11:57 AM
  2. page counter to check every 3pages printed
    By Ajay1967 in forum Programming
    Replies: 4
    Last Post: 05-30-2011, 07:17 AM
  3. Need counter to print
    By miziri in forum Access
    Replies: 1
    Last Post: 05-11-2011, 02:07 AM
  4. Incrementing Counter in Query
    By Rawb in forum Queries
    Replies: 9
    Last Post: 02-10-2011, 02:58 PM
  5. lap Counter
    By challenger in forum Access
    Replies: 4
    Last Post: 07-06-2010, 02:20 PM

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