Storing text from a check box control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kobamfo
    New Member
    • Sep 2012
    • 14

    Storing text from a check box control

    Hi Guys,
    I have a check box named "jobstat" on a form and would like to store a text value in the backend table depending on the value of the "jobstat", so I have this code:
    Code:
    Private Sub jobstat_AfterUpdate()
    Select Case Me![jobstat]
      Case 1
        Me![txtVal] = "Complete"
      Case 0
        Me![txtVal] = "Incomplete"
    End Select
    the "txtVal" field on the form has its Visibility set to "No" and it is solely responsibly for collecting and committing the text "complete" or "incomplete " to the table.
    Now the problem! the "Incomplete " works fine when "jobstat" is unchecked but when checked, the table field which has a data type of Yes/No which is also the Control Source for "txtVal" does not get the "complete" value, Why? What am I doing wrong or not doing?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    The quick explanation is that the True or Yes in this case is represented as -1, not 1.

    I suggest you look a bit at simple debugging. Adding a breakpoint @line 2 for instance, would allow you to check the value of me![jobstat] while hovering the mouse over the variable in the code. That would likely have helped you realise this yourself. Another option is to use Debug.Print or msgbox statements. These are quite usefull as well.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      How can that be true?

      If a field is of type Yes/No then it is Boolean and is unable to take the String value of "Incomplete ", whereas you indicate that it has. Something in what you say must be incorrect, and as such, is impossible to work with.

      PS. I should have refreshed before posting. Smiley noticed another problem. The one you were trying to ask about. You should understand that VBA provides terms for True and False such that you can use the code :
      Code:
      Private Sub jobstat_AfterUpdate()
      Select Case Me![jobstat]
        Case True
          'Something that makes sense here
        Case False
          'Something that makes sense here
      End Select
      Last edited by NeoPa; Nov 9 '12, 08:55 PM.

      Comment

      Working...