Results 1 to 13 of 13
  1. #1
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10

    Question Check box to add 0.5 to unbound text box


    Hi guys, im new here and have had a dig around and cannot find a answer to my question.

    I have form, and on this form there is a subform with a series of check boxes to represent the days of the month and am and pm. When i check a box (for example monday the 1st AM) i need 0.5 to be placed in a unbound text box, and then a further .5 to be added to the same text box when i tick the next monday AM.....

    A simple solution to my problem would be to set the yes/no values of check box to 0 for no and .5 for yes instead of -1 and 0 but from what i can tell this isnt possible!

    I hope this makes sence and is do able, thanks in advance.

    Ginge

  2. #2
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Seems to me that you have 62 check boxes - and that's only for one month!

    What you need to do is program an event handler for the After Update event of each check box. The outline structure of the code is:

    If Me.chk?? then
    Me.txtAccumulator = Me.txtAccumulator + 0.5
    Else
    Me.txtAccumulator = Me.txtAccumulator - 0.5
    End If

    Five lines of code times sixty-two boxes - good luck.

    There are other looping solutions if you're interested.

  3. #3
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10

    thanks man

    Thanks mate, ill give that a go this instant

  4. #4
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    am i adding this code to the check box its self or to the unbound textbox? it just hightlights the me.chk?? in red....it does not like that lol

  5. #5
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    You add it for each check box. Here's an example:

    Code:
     
    Private Sub Chk1_AfterUpdate()
     
    If Me.chk1 Then
    Me.txtAccumulator = Me.txtAccumulator + 0.5
    Else
    Me.txtAccumulator = Me.txtAccumulator - 0.5
    End If
     
    End Sub
    You must, of course, use your own names.

  6. #6
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    thanks man ill give that ago when im back in the office on monday

  7. #7
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    If you do have 62 check boxes then you may find the offered solution somewhat verbose.

    An alternative is to loop through every control on the form and test whether it is a check box. If so and if it is true then add 0.5 to the accumulator. You could trigger this from a command button or, if you have to, put a one-liner behind every text box. Would cut the number of lines of code by at least 50% by taking a slight performance hit.

    Oh, by the way, I forgot to mention that it is a good idea to set the defauult value of your accumulator to zero since 0.5 + Null = Null.

  8. #8
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    ok, well for some reason i just could not get that to do what i wanted do i have opted to do this. Instead of having checkboxes i now have command buttons that add .5 to a unbound text box

    Private Sub button_Click()
    me.textbox = nz(me.textbox,0) +0.5
    end sub

    this works fine. But i now have one small hurdle to jump, can i make a button change colour once pressed or appear to stay depressed and then when i go on to the next record i need the button to reset to unclicked and the checkbox value to reset to 0. thanks for all your help so far.

    ginge

  9. #9
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    can i make a button change colour once pressed or appear to stay depressed
    Use a toggle button.

  10. #10
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    Quote Originally Posted by Rod View Post
    Use a toggle button.
    i just realise this after putting a line of code behind 64 controle boxes!! god dam! dont suppose there is a way to quickly swap all the code to 64 toggle buttons?! lol.....going to have to do this manualy arnt i.

    scrap that, just realised that i can but the same code behind a check box "on click" which works fine! soooooooo is there a simple little bit of code that will clear all check boxes when i go to the next record ?

    talk about long way round! lol

    thanks man

  11. #11
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    [Ctrl]+H works wonders! Sorry, posted that before I read the , 'Scrap that' bit.

  12. #12
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    haha of course find and replace, iv just copied and pasted 115 times, coz im stupid lol! thank for all your help. im sure ill be able to find the answer to my last question hidden in the forum some where

    peace guys

  13. #13
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    This might help:

    Code:
     
    Private Sub ClearCheckBoxes()
     
    Dim ctl As Access.Control
     
    For Each ctl In Me.Controls
    If TypeOf ctl Is Access.CheckBox Then ctl = 0
    Next
     
    End Sub

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

Similar Threads

  1. Referencing unbound text box on report
    By EffenNewGuy in forum Reports
    Replies: 8
    Last Post: 06-22-2011, 11:07 AM
  2. Input data In unbound text box
    By chu3w in forum Forms
    Replies: 1
    Last Post: 04-01-2010, 10:21 AM
  3. Unbound Text box in reports
    By Overdive in forum Reports
    Replies: 1
    Last Post: 02-17-2010, 09:52 AM
  4. Transfer Text to Unbound Form
    By DWS in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 08:04 AM
  5. Unbound text box truncating text
    By gddrew in forum Forms
    Replies: 0
    Last Post: 03-02-2006, 11:26 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