I have been able to make my Loop to look for Empty TextBoxes on my userform with 5 Tabs and it is working up to a fashion. Not as I want it to work. I have 23 textbox to be completed. I have written individual code for each TextBox to validate but that is a lot of code!!! thought a Loop will work better.
My help call is the following:
I am trying to change the ForeColor as well if the Textbox is empty string. The Backcolor if the textbox is empty os working fine.
I am trying to SetFocus to the first textbox that has empty string. I think it has something to do with the fact that I have 5 Tabs and a lot of different Frames on the Tabs.
This is the code for the Loop.
I have also included some of the code which I originally wrote to do the validating for each individual textbox. there are 23 of them.
PLEASE I need help seriously.
<pre>
Private Function EverythingFilledIn() As Boolean
'CREATING FUNCTION TO STEAMLINE CODE TO USE DURING VALIDATION OF CONTROLS ON USERFORM
'MAKES CODE ESIER TO READ AND MORE FLEXIBLE TO MAKE CHANGES TO
'LOOP OVER ALL CONTROLS ON THE FORM INSTEAD OF ONE BY ONE
Dim ctl As MSForms.Control
'set variable that will look at every single Control on the form be it Text, Date, ComboBox etc use MSForms.Control as this will make certian that we always use contols from MSForms contol - to avoid duplication from other controls
Dim txt As MSForms.TextBox
'variable so thaty code can be made more robust and to make changes so that the intellisense will work
Dim AnythingMissing As Boolean
'to find if anything is missing in textbox to SetFocus to that textbox
'assume everything on userform has been filled in for procedure to work properly
EverythingFilledIn = True
AnythingMissing = False
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
Set txt = ctl 'transfer what is in the ctl variable to txt variable - will make intellisece work as it should
If txt.Value = "" Then 'check if Contols value is an empty string
txt.BackColor = rgbHotPink 'if Contols value is an empty string change Backcolor to Pink
'Controls(ctl.Name & "lbl").ForeColor = rgbFireBrick
If Not AnythingMissing Then ctl.SetFocus
AnythingMissing = True
EverythingFilledIn = False
End If
End If
Next ctl
End Function
</pre>
<pre>
Private Function EverythingFilledIn() As Boolean
'CREATING FUNCTION TO STEAMLINE CODE TO USE DURING VALIDATION OF CONTROLS ON USERFORM
'MAKES CODE ESIER TO READ AND MORE FLEXIBLE TO MAKE CHANGES TO
'LOOP OVER ALL CONTROLS ON THE FORM INSTEAD OF ONE BY ONE
Dim ctl As MSForms.Control
'set variable that will look at every single Control on the form be it Text, Date, ComboBox etc use MSForms.Control as this will make certian that we always use contols from MSForms contol - to avoid duplication from other controls
Dim txt As MSForms.TextBox
'variable so thaty code can be made more robust and to make changes so that the intellisense will work
Dim AnythingMissing As Boolean
'to find if anything is missing in textbox to SetFocus to that textbox
'assume everything on userform has been filled in for procedure to work properly
EverythingFilledIn = True
AnythingMissing = False
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
Set txt = ctl 'transfer what is in the ctl variable to txt variable - will make intellisece work as it should
If txt.Value = "" Then 'check if Contols value is an empty string
txt.BackColor = rgbHotPink 'if Contols value is an empty string change Backcolor to Pink
'Controls(ctl.Name & "lbl").ForeColor = rgbFireBrick
If Not AnythingMissing Then ctl.SetFocus
AnythingMissing = True
EverythingFilledIn = False
End If
End If
Next ctl
End Function
</pre>
My help call is the following:
I am trying to change the ForeColor as well if the Textbox is empty string. The Backcolor if the textbox is empty os working fine.
I am trying to SetFocus to the first textbox that has empty string. I think it has something to do with the fact that I have 5 Tabs and a lot of different Frames on the Tabs.
This is the code for the Loop.
I have also included some of the code which I originally wrote to do the validating for each individual textbox. there are 23 of them.
PLEASE I need help seriously.
<pre>
Private Function EverythingFilledIn() As Boolean
'CREATING FUNCTION TO STEAMLINE CODE TO USE DURING VALIDATION OF CONTROLS ON USERFORM
'MAKES CODE ESIER TO READ AND MORE FLEXIBLE TO MAKE CHANGES TO
'LOOP OVER ALL CONTROLS ON THE FORM INSTEAD OF ONE BY ONE
Dim ctl As MSForms.Control
'set variable that will look at every single Control on the form be it Text, Date, ComboBox etc use MSForms.Control as this will make certian that we always use contols from MSForms contol - to avoid duplication from other controls
Dim txt As MSForms.TextBox
'variable so thaty code can be made more robust and to make changes so that the intellisense will work
Dim AnythingMissing As Boolean
'to find if anything is missing in textbox to SetFocus to that textbox
'assume everything on userform has been filled in for procedure to work properly
EverythingFilledIn = True
AnythingMissing = False
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
Set txt = ctl 'transfer what is in the ctl variable to txt variable - will make intellisece work as it should
If txt.Value = "" Then 'check if Contols value is an empty string
txt.BackColor = rgbHotPink 'if Contols value is an empty string change Backcolor to Pink
'Controls(ctl.Name & "lbl").ForeColor = rgbFireBrick
If Not AnythingMissing Then ctl.SetFocus
AnythingMissing = True
EverythingFilledIn = False
End If
End If
Next ctl
End Function
</pre>
<pre>
Private Function EverythingFilledIn() As Boolean
'CREATING FUNCTION TO STEAMLINE CODE TO USE DURING VALIDATION OF CONTROLS ON USERFORM
'MAKES CODE ESIER TO READ AND MORE FLEXIBLE TO MAKE CHANGES TO
'LOOP OVER ALL CONTROLS ON THE FORM INSTEAD OF ONE BY ONE
Dim ctl As MSForms.Control
'set variable that will look at every single Control on the form be it Text, Date, ComboBox etc use MSForms.Control as this will make certian that we always use contols from MSForms contol - to avoid duplication from other controls
Dim txt As MSForms.TextBox
'variable so thaty code can be made more robust and to make changes so that the intellisense will work
Dim AnythingMissing As Boolean
'to find if anything is missing in textbox to SetFocus to that textbox
'assume everything on userform has been filled in for procedure to work properly
EverythingFilledIn = True
AnythingMissing = False
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
Set txt = ctl 'transfer what is in the ctl variable to txt variable - will make intellisece work as it should
If txt.Value = "" Then 'check if Contols value is an empty string
txt.BackColor = rgbHotPink 'if Contols value is an empty string change Backcolor to Pink
'Controls(ctl.Name & "lbl").ForeColor = rgbFireBrick
If Not AnythingMissing Then ctl.SetFocus
AnythingMissing = True
EverythingFilledIn = False
End If
End If
Next ctl
End Function
</pre>