Access VBA Programming : How to Loop Through Controls on a UserForm.
ð Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðē Enroll Now: https://bit.ly/2WcbRhX
[#YouTube]
Part 1: https://youtu.be/-ukT2wE9Yhw
Part 1: https://youtu.be/-ukT2wE9Yhw
Part 2: https://youtu.be/tZ_tPEqXEyE
[Source Code]
Option Compare Database
Private Sub Form_Load()
Dim DataList As String
ListBox1.RowSource = ""
ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = "1cm;3cm"
ListBox1.FontSize = 16
ListBox2.RowSource = ""
ListBox2.ColumnCount = 2
ListBox2.ColumnWidths = "1cm;3cm"
ListBox2.FontSize = 16
End Sub
Private Sub ListBox1_Click()
On Error Resume Next
Dim rowNumA As Integer
rowNumA = Me.ListBox1.ListIndex
Me.txtSelected1 = Me.ListBox1.Column(0, rowNumA) & "-" & Me.ListBox1.Column(1, rowNumA)
End Sub
On Error Resume Next
Dim rowNumA As Integer
rowNumA = Me.ListBox1.ListIndex
Me.txtSelected1 = Me.ListBox1.Column(0, rowNumA) & "-" & Me.ListBox1.Column(1, rowNumA)
End Sub
Private Sub ListBox2_Click()
On Error Resume Next
Dim rowNumB As Integer
rowNumB = Me.ListBox2.ListIndex
Me.txtSelected2 = Me.ListBox2.Column(0, rowNumB) & "-" & Me.ListBox2.Column(1, rowNumB)
End Sub
On Error Resume Next
Dim rowNumB As Integer
rowNumB = Me.ListBox2.ListIndex
Me.txtSelected2 = Me.ListBox2.Column(0, rowNumB) & "-" & Me.ListBox2.Column(1, rowNumB)
End Sub
Private Sub cmdAddList_Click()
ListBox1.RowSource = ""
ListBox2.RowSource = ""
txtSelected1 = ""
txtSelected2 = ""
Call checkCondition1
End Sub
ListBox1.RowSource = ""
ListBox2.RowSource = ""
txtSelected1 = ""
txtSelected2 = ""
Call checkCondition1
End Sub
Private Sub checkCondition1()
Dim ct As Control
Dim chkb As CheckBox
For Each ct In Me.Controls
If TypeOf ct Is CheckBox Then
Set chkb = ct
If ct = -1 Then ' - True
Select Case Left(ct.Name, 5)
Case Is = "chkCP"
ListBox1.AddItem "1, C/C++"
Case Is = "chkJa"
ListBox1.AddItem "2, Java"
Case Is = "chkVB"
ListBox1.AddItem "3, VB .Net"
Case Is = "chkCS"
ListBox1.AddItem "4, C# .Net"
Case Is = "chkRu"
ListBox1.AddItem "5, Ruby"
Case Is = "chkPy"
ListBox1.AddItem "6, Python"
Case Is = "chkCo"
ListBox1.AddItem "7, Cobol"
Case Is = "chkPe"
ListBox1.AddItem "8, Perl"
End Select
Else '- False
Select Case Left(ct.Name, 5)
Case Is = "chkCP"
ListBox2.AddItem "1, C/C++"
Case Is = "chkJa"
ListBox2.AddItem "2, Java"
Case Is = "chkVB"
ListBox2.AddItem "3, VB .Net"
Case Is = "chkCS"
ListBox2.AddItem "4, C# .Net"
Case Is = "chkRu"
ListBox2.AddItem "5, Ruby"
Case Is = "chkPy"
ListBox2.AddItem "6, Python"
Case Is = "chkCo"
ListBox2.AddItem "7, Cobol"
Case Is = "chkPe"
ListBox2.AddItem "8, Perl"
End Select
End If
End If
Next ct
End Sub
Dim ct As Control
Dim chkb As CheckBox
For Each ct In Me.Controls
If TypeOf ct Is CheckBox Then
Set chkb = ct
If ct = -1 Then ' - True
Select Case Left(ct.Name, 5)
Case Is = "chkCP"
ListBox1.AddItem "1, C/C++"
Case Is = "chkJa"
ListBox1.AddItem "2, Java"
Case Is = "chkVB"
ListBox1.AddItem "3, VB .Net"
Case Is = "chkCS"
ListBox1.AddItem "4, C# .Net"
Case Is = "chkRu"
ListBox1.AddItem "5, Ruby"
Case Is = "chkPy"
ListBox1.AddItem "6, Python"
Case Is = "chkCo"
ListBox1.AddItem "7, Cobol"
Case Is = "chkPe"
ListBox1.AddItem "8, Perl"
End Select
Else '- False
Select Case Left(ct.Name, 5)
Case Is = "chkCP"
ListBox2.AddItem "1, C/C++"
Case Is = "chkJa"
ListBox2.AddItem "2, Java"
Case Is = "chkVB"
ListBox2.AddItem "3, VB .Net"
Case Is = "chkCS"
ListBox2.AddItem "4, C# .Net"
Case Is = "chkRu"
ListBox2.AddItem "5, Ruby"
Case Is = "chkPy"
ListBox2.AddItem "6, Python"
Case Is = "chkCo"
ListBox2.AddItem "7, Cobol"
Case Is = "chkPe"
ListBox2.AddItem "8, Perl"
End Select
End If
End If
Next ct
End Sub
Private Sub chkAllNone_Click()
On Error Resume Next
Dim ctrl As Control
Dim chkBox As CheckBox
Set chkBox = ctrl
If Me.chkAllNone.Value = True Then
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = True
End If
Next ctrl
Else
'ctrl.Value = False
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
End If
Next ctrl
End If
End Sub
On Error Resume Next
Dim ctrl As Control
Dim chkBox As CheckBox
Set chkBox = ctrl
If Me.chkAllNone.Value = True Then
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = True
End If
Next ctrl
Else
'ctrl.Value = False
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
End If
Next ctrl
End If
End Sub
Private Sub CheckAllNone()
Select Case Me.chkCobol + Me.chkCPlusPlus + Me.chkCSharp + Me.chkJava + _
Me.chkPerl + Me.chkPython + Me.chkRuby + Me.chkVB
Case Is = 0
Me.chkAllNone.Value = 0 '0 = UnChecked
Case Is = -8
Me.chkAllNone.Value = -1 '-1 = checked
Case Else
Me.chkAllNone.Value = Null
End Select
End Sub
Select Case Me.chkCobol + Me.chkCPlusPlus + Me.chkCSharp + Me.chkJava + _
Me.chkPerl + Me.chkPython + Me.chkRuby + Me.chkVB
Case Is = 0
Me.chkAllNone.Value = 0 '0 = UnChecked
Case Is = -8
Me.chkAllNone.Value = -1 '-1 = checked
Case Else
Me.chkAllNone.Value = Null
End Select
End Sub
Private Sub chkCobol_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkCPlusPlus_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkCSharp_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkJava_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkPerl_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkPython_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkRuby_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
Private Sub chkVB_Click()
Call CheckAllNone
End Sub
Call CheckAllNone
End Sub
My Twitter
https://twitter.com/#!/IBasskung
https://twitter.com/#!/IBasskung
My Facebook
https://www.facebook.com/CodeAMinute
https://www.facebook.com/CodeAMinute
Thank you very much.
āļāļāļāļุāļāļāļĢัāļ.
āļāļāļāļุāļāļāļĢัāļ.
Comments
Post a Comment