Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 03-19-2019, 09:31 PM
ScottyBee ScottyBee is offline Loop through Multiple Boolean Variables Windows 10 Loop through Multiple Boolean Variables Office 2016
Novice
Loop through Multiple Boolean Variables
 
Join Date: Mar 2019
Location: Portland, Oregon
Posts: 12
ScottyBee is on a distinguished road
Default Loop Through Boolean Values

Hello Guess,

Yes, my latest code was to augment the code you posted earlier shown here:

Private Sub btnOK_Click()
Dim i As Integer, aCtl As Control
For i = 1 To 8
With Me.Controls("TextBox" & i)
If .Value = "" Then
MsgBox "Nothing in this one"
.SetFocus
Exit Sub
Else
MsgBox .Name & vbCr & .Value
End If
End With
Next i
End Sub

I adapted it a little but it worked great in identifying null values and returning focus to the textbox control that needed to be entered.

My most recent post was trying to take the ideas you gave me to solve another issue. That issue involves checking that all textboxes have been changed from their default values. A snapshot of my user form is shown here:

User Form.JPG

I added your code to the "Check for Nulls" command button and it work like a charm. As you can see from the user form there are default values presented to the user. They are required to enter all fields. The code you provided catches when the user presses delete then tabs to the next field leaving the previous one blank.

Taking your idea, I tried to code the "Verify all Fields Updated" button to check for changes. In a module, I have declared public boolean variables to be used in the Change Event for each textbox control on the form. When the textbox is changed, then the code changes the boolean value to True.

I was trying to think of a way to loop all of the boolean variables like you did with the text objects but I guess that cannot be done. It looks like I will have to text them individually.

I did have a question about your code here:

Sub UserForm_Initialize()
Me.TextBox1 = "Initial value"
Me.PreTextBox1 = "Initial value" 'each visible TextBox has a hidden partner prefilled with same initial content
End Sub
Sub UserForm_Validate()
If Me.TextBox1 <> Me.PreTextBox1 then
MsgBox "A change was detected"
end if
End Sub

Questions:

1. Since I have 8 textboxes, I assume I will duplicate your code for each control and have the focus returned to the control that did not change. I also have 3 combo boxes but will code them later.

2. Looks like I have two approaches to this issue. Use your logic using hidden textboxes or use a change event for each control with code to test for any change? Is any better than the other?

3. A final validation for my form will involve checking the textbox values for a fixed number of numerical characters. Are you aware of any resources online going over VBA validation techniques for form texboxes or other controls?

This will be a project a week or two down the road.

Thanks much!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate template-based letter with multiple variables shallaes Word VBA 5 07-12-2018 12:18 AM
Multiple Problems with a loop Radtastic10 Excel Programming 3 06-09-2017 09:38 AM
Testing multiple values of two independant variables and charting results sgcannon Excel 0 10-20-2015 10:10 AM
Array to iterate through variables and trap blank variables Marrick13 Word VBA 5 08-04-2015 06:19 AM
Same values of variables in word add-in are being shared across multiple document naq.abbas@gmail.com Word 0 01-13-2014 10:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft