ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Use code in a modul (https://www.excelbanter.com/excel-programming/428389-use-code-modul.html)

alvin Kuiper

Use code in a modul
 
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


Chip Pearson

Use code in a modul
 

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)







On Tue, 12 May 2009 13:31:03 -0700, alvin Kuiper
wrote:

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


Dave Peterson

Use code in a modul
 
Check your older thread.

alvin Kuiper wrote:

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


--

Dave Peterson

Dave Peterson

Use code in a modul
 
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)?

alvin Kuiper wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com