Results 1 to 11 of 11
  1. #1
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Boolean code help (2002)

    I'm getting really good at writing code that doesn't work!

    I need to prevent blnActiveTeamMem from being checked (true) if blnGraduate is false, and to set focus on blnGraduate if it is, indeed, false. Also, I suppose, I would need to have blnActiveTeamMem set to false if blnGraduate were unchecked (false) for some unknown reason. BTW, would there be a way to change the back color of blnGraduate when it has focus (the label that is)?
    <pre>Private Sub blnActiveTeamMem_BeforeUpdate(Cancel As Integer)
    If [blnGraduate] = False Then
    MsgBox "Team member has not completed training.", vbInformation
    Me.blnGraduate.SetFocus
    Exit Sub
    Else
    [blnActiveTeamMem] = False
    End If
    End Sub</pre>

    Any and all help greatly appreciated. Have a great weekend!
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Boolean code help (2002)

    Always look on the bright side: It's better to be good at writing code that doesn't work than to be bad at writing code that doesn't work.

    The following code may do what you want:
    <pre>Private Sub blnActiveTeamMem_AfterUpdate()

    If blnActiveTeamMem = True Then
    If blnGraduate = False Then
    blnActiveTeamMem = False
    blnGraduate.SetFocus
    End If
    End If

    End Sub

    Private Sub blnGraduate_GotFocus()

    lblBlnGraduate.BackStyle = 1

    End Sub

    Private Sub blnGraduate_LostFocus()

    lblBlnGraduate.BackStyle = 0

    End Sub</pre>

    The GotFocus and LostFocus code assumes that the label is normally transparent, and that you've set the label's BackColor property to something different from the surrounding BackColor. If the label is normally non-transparent, you'd instead use the GotFocus event to change the label's BackColor to a different color and then reset it to the normal color on LostFocus.

    Note that I used the AfterUpdate event rather than the BeforeUpdate event because the BeforeUpdate event doesn't let you change the focus (as far as I know) if you're setting Cancel to True (which is how you'd use BeforeUpdate to prevent a change in the checkbox's value).

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Boolean code help (2002)

    Another approach to these sorts of question is to set the enabled property of a control to false in situations where you don't want a user to be able to put a value into a control (or click a command button.)
    This usually requires code in two places : the after update event of the control that is the prerequisite, and the on current event (to deal with moving through old records.)

    In design view you would set the enabled property of blnActiveTeamMem to false.

    Private Sub blnGraduate_AfterUpdate()
    If [blnGraduate] = False Then
    Me.blnActiveTeamMem = false
    Me.blnActiveTeamMem.enabled = false
    Else
    Me.blnActiveTeamMem.enabled = true
    end sub

    You would also have exactly the same code in the oncurrent event of the form
    Regards
    John



  4. #4
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    Thanks st3333ve, I'll give this a go and see how it works.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  5. #5
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    Thanks John, I will try this solution as well.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  6. #6
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    st3333ve:

    Thanks, once agin, for your generous code; you provided a solution in direct response to my request (and it works quite well I might add). However, and after testing John's alternative method, I find his solution to be substantially better than my approach to the problem. I do thank you for your advise, but I apparently didn't have the forethought to approach this issue with the intuitiveness that John did, least of all to establish the code for it. Again, thank you so much for your time and talents.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  7. #7
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    John:

    Thanks for offering your "alternative approach". After testing both your method and st3333ve's assistance in establishing my own, I find yours to be the better way. If the user shouldn't be checking blnTeamActiveMem unless the student was already a graduate, why would I even be offering them that option? Your willingness to address my question "out side of the box" offered me an entirely different (and better) solution. Thanks for going the extra mile! I'm quite pleased with the results.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  8. #8
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Boolean code help (2002)

    Bryan

    A variation on this technique is to set the visible property to false, instead of the enabled property.
    This just completely hides something that you don't want the user to put data into.

    The risk with both approaches is that people can get confused if they don't understand what is going on, and why they sometimes can and sometimes can't do something.
    Regards
    John



  9. #9
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    John:

    I actually discovered several other "options" that should be controlled by blnGraduate that were spread out over the form. I rearranged the landscape a bit, put all of the controls in a single area surrounded by a border, and used a label in the upper portion of the border "Controls disabled if student has not graduated". This "notice" is set to visible when blnGraduate is false.

    Thanks again John! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  10. #10
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Boolean code help (2002)

    That sounds like a very sensible solution.
    Regards
    John



  11. #11
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: Boolean code help (2002)

    Sensible?
    (Now there's a word not often associated with any of my endeavors!)
    <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •