Reuse of formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was hoping someone could assist me on this. I have several check boxes. I
want to be able to count certain ones and populate an unbound textbox with
this number. I use this number in other procedures on the form. Currently I
am using the formula for every check box on click. However, instead of doing
this, is there a way that I can place this in a module then reference it with
on click? Here is my code:

Private Sub chk1_Click()
Dim X, a, b, c, d, e, f, g As Integer

X = 0

If Me.chk1 = True Then
a = 1
Else
a = 0
End If

If Me.chk2 = True Then
b = 1
Else
b = 0
End If

If Me.chk3 = True Then
c = 1
Else
c = 0
End If

If Me.chk4 = True Then
d = 1
Else
d = 0
End If

If Me.chk5 = True Then
e = 1
Else
e = 0
End If

If Me.chk6 = True Then
f = 1
Else
f = 0
End If

If Me.chk7 = True Then
g = 1
Else
g = 0
End If

X = a + b + c + d + e + f + g

Me.NumberOfSectionsSelected = X
End Sub
thanks
 
Fysh said:
I was hoping someone could assist me on this. I have several check boxes. I
want to be able to count certain ones and populate an unbound textbox with
this number. I use this number in other procedures on the form. Currently I
am using the formula for every check box on click. However, instead of doing
this, is there a way that I can place this in a module then reference it with
on click? Here is my code:

Private Sub chk1_Click()
Dim X, a, b, c, d, e, f, g As Integer

X = 0

If Me.chk1 = True Then
a = 1
Else
a = 0
End If

If Me.chk2 = True Then [snip repetitive code]

X = a + b + c + d + e + f + g

Me.NumberOfSectionsSelected = X
End Sub

Create the procedure as a Public Function in a standard
module:

Public Function TotalChecked() as Integer
Dim frm As Form
Set frm = Forms!theform
For K = 1 to 7
TotalChecked = TotalChecked - Nz(frm("chk" & K), 0)
Next K
End Sub

Unless there is some kind of timing issue, the
NumberOfSectionsSelected text box can then use the
expression =TotalChecked()
 
That works great

thanks

Marshall Barton said:
Fysh said:
I was hoping someone could assist me on this. I have several check boxes. I
want to be able to count certain ones and populate an unbound textbox with
this number. I use this number in other procedures on the form. Currently I
am using the formula for every check box on click. However, instead of doing
this, is there a way that I can place this in a module then reference it with
on click? Here is my code:

Private Sub chk1_Click()
Dim X, a, b, c, d, e, f, g As Integer

X = 0

If Me.chk1 = True Then
a = 1
Else
a = 0
End If

If Me.chk2 = True Then [snip repetitive code]

X = a + b + c + d + e + f + g

Me.NumberOfSectionsSelected = X
End Sub

Create the procedure as a Public Function in a standard
module:

Public Function TotalChecked() as Integer
Dim frm As Form
Set frm = Forms!theform
For K = 1 to 7
TotalChecked = TotalChecked - Nz(frm("chk" & K), 0)
Next K
End Sub

Unless there is some kind of timing issue, the
NumberOfSectionsSelected text box can then use the
expression =TotalChecked()
 
Back
Top