Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check boxes

Status
Not open for further replies.

Gavuk

Programmer
Apr 16, 2003
32
GB
Hiya all,

Help needed.

got this form (access 97!!!)

I have multiple check boxes on the form that can be checked when they are checked they are suppose to turn other vales on the form to enable or disabled.

The problem is they dont all appear to fall into the:

chk_box click event.

i have tried putting them all into a option box but then you can only check one of them at a time any help would be appreciated.

Gav
 
If you want them to be working independently then you can't put them in an option group.

I need a little more info here. When you said:
The problem is they dont all appear to fall into the:
chk_box click event.


Just what did you mean?


Bob Scriver
 
Interesting question. If I understand correctly, you want to be able to handle multiple, independent checkbox values on a form.

Try coding a module-level subroutine that is called by each Click event. Pass the currently active control object to the function and use a SELECT CASE statement to determine appropriate actions.

Example:
Code:
Option Compare Database
Option Explicit

Private Sub mHandleCB(ctl As Control)
    Select Case ctl.Properties("Name")
        Case "Check0"  'Show/Hide text box Text1
            Me!Text1.Visible = ctl
            
        Case "Check1"  'Enable/Disable button Command1
            Me!Command1.Enabled = ctl
    End Select
End Sub

Private Sub Check0_Click()
    Call mHandleCB(Screen.ActiveControl)
End Sub

Private Sub Check1_Click()
    Call mHandleCB(Screen.ActiveControl)
End Sub
This allows you to handle all checkbox activities from a central spot and helps with future maintenance.

Jim Kraxberger
Developing Access solutions since 1995
jkraxberger@scp4me.com
 
Cheers Jim,

The problem is that the Click event of each check box does not appear to work everytime (except for the first one which always appears to work) so the central feature (although good) will not always fire.
 
When you say only the first time it seems to work are you saying that when you check one of the othe boxes that the properties set in the first check boxes are not reversing themselves? If this is the case then you are misunderstanding the process of setting the .enabled property. The checkboxes are totally unrelated unless you make them related through code. If CheckBox1 sets a control to .enabled = true and CheckBox2 sets a different control to .enabled = true unless you reverse the effects of checkbox1 through code here then there will be no change.

Does this seem to be the problem? Maybe if you copied the code of a couple of checkboxes OnClick procedure to this post we could see just what is going on.

Bob Scriver
 
Here is the code in question

Private Sub ChAon_Click()

If ChAon.Value = True Then
txtAonDate.Enabled = True
Else
txtAonDate.Enabled = False
End If

End Sub


Private Sub ChDWP_Click()

If ChDWP.Value = True Then
txtDWPDAte.Enabled = True
Else
txtDWPDAte.Enabled = False
End If

End Sub

as you can see it only does simple stuff but it just will not hit the chbox_click event its driving me mad! as sometimes it will hit them !! (after deleting the sub then repasting it works fine but after that i.e after a few clicks it no longer hits the click event)..
 
I have duplicated what you have described and it works perfectly as many times as I want to click the check boxes. My advise is that something is wrong with your form. For starters create a new form with just a couple of text boxes and the checkboxes on it. Put the code back in and text it out. See if moving the code to another form will solve the problem. I have seen this solve strange problems.

Bob Scriver
 
Cheers Bob,

Took it home last night (sad i know!!) ended up sticking an option box round it and then it worked ok but had to play with it for ages.

cheers again.

Gav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top