VBA problem
Can anyone help me out I am newbee at vba and I am having some problems adjusting to it although I do want to learn.
Anywayz I am using access 2003 for my project I am working on check boxes. I have a table with two fields region having the data type text and selection having the data type yes/no. I convert the table into a form add a command button which selects all the check boxes
Problem what if I have to up date the table then what how will I select all the check boxes at that time.
I am just having problems understanding how to loop check boxes
need help
[597 byte] By [
mass1978] at [2007-11-20 11:49:44]

# 1 Re: VBA problem
Sample:
Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'DO STUFF HERE
End If
Next cCont
End Sub
# 2 Re: VBA problem
Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'DO STUFF HERE
End If
Next cCont
End Sub
There are a couple of questions regarding this code
what does "me" represent
and what does "typename" represent
for example the name of my form is form region and
the name of the selection field is selection which the use has to click in other words that selection field is the check box field
and do I have to enter the value like
"if selection(ccont) = "Yes" then 'do stuff here"
# 3 Re: VBA problem
ME is the current form. Here's one of my samples:
Disables all command buttons all forms.
Option Explicit
'
' ? TypeName(ctlall) ' find out control names
' ? ctlall.name ' from the immediate window
Private Sub Form_Load()
Dim frm As Form
Dim ctlAll As Control
For Each frm In Forms
For Each ctlAll In frm
If TypeOf ctlAll Is CommandButton Then
ctlAll.Enabled = False
End If
Next ctlAll
Next frm
End Sub
Just add another layer to loop thru all checkboxes until you find the one you want to edit.
# 4 Re: VBA problem
Private Sub Command4_Click()
Dim Selection As Control
For Each Selection In frm_region.Controls
If TypeName(Selection) = "YES" Then
'YES'
End If
Next Selection
End Sub
is this code correct
I have replaced me with my form name form_region
and I have replaced ccont with selection