Passing check box controls to a function

D

Dennis

I want to call a function in a module from a button press on a form. I want
to pass the name of a check box control on my form into this function and
then use this in my function to uncheck the check box on the form. How do I
pass it and and how do I reference it in my function ?
I do this because I have several check boxes on the form and I wanted 1
common routine in a module with variables passed into it.

e.g. Call MyFunction(chkQ1)

Public Function MyFunction (ctlChkBox as Checkbox)
Forms!MyForm!ctlChBox = False
End Function
 
S

Stefan Hoffmann

hi Dennis,
I do this because I have several check boxes on the form and I wanted 1
common routine in a module with variables passed into it.

e.g. Call MyFunction(chkQ1)

Public Function MyFunction (ctlChkBox as Checkbox)
Forms!MyForm!ctlChBox = False
End Function
You have the following two possibilities:

--
Option Compare Database
Option Explicit

Private Sub cmdChangeCheckBox_Click()

byName "yourCheckBox"
byControl yourCheckBox

End Sub

Private Sub byName(ACheckBoxName As String)

Dim ac As Access.Control

Set ac = Me(ACheckBoxName)
If TypeOf Me(ACheckBoxName) Is Access.CheckBox Then
ac.Value = True
End If
Set ac = Nothing

End Sub

Private Sub byControl(ACheckBox As Access.CheckBox)

ACheckBox.Value = False

End Sub
 
D

Dennis

Thanks, the 2nd one is the one I wanted

Stefan Hoffmann said:
hi Dennis,

You have the following two possibilities:

--
Option Compare Database
Option Explicit

Private Sub cmdChangeCheckBox_Click()

byName "yourCheckBox"
byControl yourCheckBox

End Sub

Private Sub byName(ACheckBoxName As String)

Dim ac As Access.Control

Set ac = Me(ACheckBoxName)
If TypeOf Me(ACheckBoxName) Is Access.CheckBox Then
ac.Value = True
End If
Set ac = Nothing

End Sub

Private Sub byControl(ACheckBox As Access.CheckBox)

ACheckBox.Value = False

End Sub
--


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top