Use code in a modul

A

alvin Kuiper

Hi i use this on a checkbox event
Dim i As Integer
Dim a As Integer
a = 0
For i = 1 To 4
If Me.Controls("chk_ci" & i).Value = True Then
a = a + 1
End If
Next

This works but if i make the code in a modul and use it
i get an error on ME - and if i delete me I get an error on Controls
and if I just use :
If "chk_ci" & i.Value = True Then

Then i get an error on the varable i

Can someone help here?

Alvin
 
C

Chip Pearson

Instead of
If "chk_ci" & i.Value = True Then

use

Me.Controls("chk_ci" & CStr(i.Value)).Value = True Then

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

Dave Peterson

Check your older thread.

alvin said:
Hi i use this on a checkbox event
Dim i As Integer
Dim a As Integer
a = 0
For i = 1 To 4
If Me.Controls("chk_ci" & i).Value = True Then
a = a + 1
End If
Next

This works but if i make the code in a modul and use it
i get an error on ME - and if i delete me I get an error on Controls
and if I just use :
If "chk_ci" & i.Value = True Then

Then i get an error on the varable i

Can someone help here?

Alvin
 
D

Dave Peterson

Where are your checkboxes?

On a worksheet or in a userform?

If they're on a userform, see your other thread.

If they're on a worksheet, what type are they?

Are they from the Forms toolbar or from the Control toolbox toolbar?

And where is this code?

Is it behind a worksheet (called from a click of a commandbutton from the
control toolbox toolbar)?

Or is it in a General module (called from click of a button from the Forms
toolbar)?
 

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