Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    ChilliChowder is offline Novice
    Windows XP Access 2000
    Join Date
    May 2012
    Posts
    4

    Question Traffic Survey Field - +/-1 increment to field on every button click - Help Please!

    Hello All,

    First time poster and learning Access as I go, so please be gentle!



    I have a form that I am designing in Access 2000 and copying to a handheld tablet for a carriageway condition survey.

    As part of this survey we want to count the number of cars passing during a ten minute period on site. This data will be recorded in a 'Traffic Count' field which currently consists of a combo box with a drop down containing values 1-60. The intention being that the surveyor enters the number of cars once 10 mins is up.

    However, because the surveyor will also be concentrating on other things while on site I don't want them to need to count every car, but rather just records a 'click' every time car passes, and on each click the form increases the value of 'Traffic Count' field by 1.

    I would like to add a pair of +/- buttons that would result in the 'Traffic Count' field being increase/decreased by 1 each time they are clicked. (I want to add the ability to decrease just in case of mistakes).

    I imagine this is quite straight forward and I have had a good look online but failed to find exactly what I need - and I do not have the knowledge yet to alter similar code I did find.

    Thanks - All help much appreciated!

    Dan

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Something like this will do it:
    Code:
    Private Sub PlusButton_Click()
     Me.TrafficCount = Nz(Me.TrafficCount, 0) + 1
    End Sub
    Code:
    Private Sub MinusButton_Click()
    If Not IsNull(Me.TrafficCount) And Me.TrafficCount <> 0 Then
      Me.TrafficCount = Me.TrafficCount - 1
    End If
    End Sub
    If you're pressed for space on your Form, there's also an ActiveX Control named UpDown Control (at least that's the name in 2007; in earlier versions it was called a Spinbutton Control) that is designed for this. That code would be like this:
    Code:
    Private Sub TrafficUpDown_UpClick()
      Me.TrafficCount = Nz(Me.TrafficCount, 0) + 1
    End Sub
    Code:
    Private Sub TrafficUpDown_DownClick()
    If Not IsNull(Me.TrafficCount) And Me.TrafficCount <> 0 Then
      Me.TrafficCount = Me.TrafficCount - 1
    End If
    End Sub
    But using larger, custom buttons with the first two code samples above may be better, given that this is being used on a handheld device.

    Linq ;0)>
    Last edited by Missinglinq; 05-14-2012 at 02:47 PM.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Create a button. In the On Click event of the button, use this:
    Code:
    Me.txtCounter = Nz(Me.txtCounter, 0) + 1
    Change txtCounter to the name of the text box in which the "count" is to be displayed.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Sorry missinglinq,
    Your reply wasn't there when I started.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Don't you hate when that happens, Bob? My hound invariably comes in, begging to go out, when I'm writing a complicated response, and I always forget to check for new replies before hitting the 'send' button!

    Linq ;0)>

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by Missinglinq View Post
    Don't you hate when that happens, Bob? My hound invariably comes in, begging to go out, when I'm writing a complicated response, and I always forget to check for new replies before hitting the 'send' button!
    Exactly, but my distraction wasn't a dog. It was my wife.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Well, we won't go there!

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Probably best
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    ChilliChowder is offline Novice
    Windows XP Access 2000
    Join Date
    May 2012
    Posts
    4
    Guys,

    Thank you both very much. Both worked great - Much appreciated....

    I imagine I'll be back very soon :-)

    Dan

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by ChilliChowder View Post
    Guys,
    Thank you both very much. Both worked great - Much appreciated....
    Glad we could help.

    I imagine I'll be back very soon :-)
    You will be welcome. I'm sure someone will be here.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    ChilliChowder is offline Novice
    Windows XP Access 2000
    Join Date
    May 2012
    Posts
    4

    I lied...

    Back sooner than intended... In my rush to get out of the office yesterday I didn't actually test this but didn't want to leave it another day without thanking you both - and thus thanked you precipitously! Foolish.

    So now I am back with my tail between my legs as I am getting a compile error - 'method or data not found'

    I have only added the plus button so far, the code is as follows:

    Private Sub Plusbutton_Click()
    Me.SPN_Traffic_Count = Nz(Me.SPN_Traffic_Count, 0) + 1
    End Sub

    When the debugger runs the first underlined section is appearing highlighted in yellow.

    I have added and re-added the button and code several times hoping for a different result, as well as playing around with the field type/values in hope that something will have an effect - No luck.

    Any suggestions or help much appreciated.

    Thanks again

    Dan

  12. #12
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Well, you said you'd be back!

    With

    Private Sub Plusbutton_Click()

    being hi-lighted, and the given error message, it would seem that Access cannot find a Command Button named Plusbutton. Check to make sure that you changed the name of the button to this after placing it on your Form.

    Linq ;0)>

  13. #13
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    oops, miss read something :P

  14. #14
    ChilliChowder is offline Novice
    Windows XP Access 2000
    Join Date
    May 2012
    Posts
    4
    Thanks for the reply Linq - I was back sooner than expected

    The command button is defintely named 'Plusbutton'. I actually created the event command by right clicking on the button and then going to On Click event, so Access created the 'Private sub Plusbutton' text itself.

    I forgot to add in my previous post that the second underlined section 'SPN_Traffic_Count'is highlighted in blue when the debugger first runs - before I click 'OK' and the Private Sub Plusbutton_Click() is highlighted in yellow. Don't know if that tells you anything else?

    By the way - Sorry I can't add any screen shot images, our computer system is still Windows 2000 and our version of Internet Explorer doesn't like these forums!

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Screen shots are very seldom of any value when trouble-shooting long distance, as it were. Attaching a copy of your smile, on the other hand, would be very helpful.

    To attach your file for analysis:
    • Make a copy of your file
    • Remove confidential data
    • Do a Compact & Repair
    • Zip file if over 2 mb
    • Attach file to a post. Attachment Manager is below the Advanced post editor window.

    If you'd care to do that I'd be glad to take a look at it. The Access Gnomes have a bad habit of hi-lighting a line other than the real culprit when things go awry!

    Linq ;0)>

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-20-2012, 01:59 PM
  2. Increment Field Value
    By Malseun in forum Access
    Replies: 9
    Last Post: 02-03-2012, 04:55 AM
  3. Replies: 7
    Last Post: 01-12-2011, 08:59 AM
  4. Increment a value on button click
    By michaeljohnh in forum Programming
    Replies: 9
    Last Post: 08-25-2010, 10:01 AM
  5. How to Increment A Number Field
    By Advanced in forum Programming
    Replies: 3
    Last Post: 01-27-2010, 02:36 PM

Tags for this Thread

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