Group non visible Textbox remove focus

ag_122

New Member
Joined
Mar 15, 2020
Messages
31
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi
I have a code below. Is there a way were the macro skip or not focus on invisible textbox
And i dont want to change the name of the textbox


Macro below

Dim ctrl As Control

Dim EntryRequired As Boolean



For Each ctrl In Me.Frame161.Controls

Select Case TypeName(ctrl)

Case "TextBox", "ComboBox"

If Not EntryRequired Then

EntryRequired = CBool(Len(ctrl.Text) = 0)

If EntryRequired Then ctrl.SetFocus



End If

ctrl.BackColor = IIf(Len(ctrl.Text) = 0, &HC0C0FF, vbWhite)



End Select

Next

If EntryRequired Then

MsgBox "Please fill the Info above to proceed", 48, "Entry Required"





End If
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

try changing this line

VBA Code:
EntryRequired = CBool(Len(ctrl.Text) = 0)

to this

VBA Code:
EntryRequired = CBool(Len(ctrl.Text) = 0) And CBool(ctrl.Visible)

and see if this does what you want

Dave
 
Upvote 0
Hi,

try changing this line

VBA Code:
EntryRequired = CBool(Len(ctrl.Text) = 0)

to this

VBA Code:
EntryRequired = CBool(Len(ctrl.Text) = 0) And CBool(ctrl.Visible)

and see if this does what you want

Dave
Hi Dave
Im still getting an error below

"Run time error 2110
Cant move focus to the control because it is invisible, not enabled or a type does not accept the focus"

And i have some textboxs that are invisible
 
Upvote 0
Very curious

Try this change

VBA Code:
If ctrl.Visible And Not EntryRequired Then

EntryRequired = CBool(Len(ctrl.Text) = 0)

etc etc

Dave
 
Upvote 0
Hi dave im still getting an error

Ill attach the error
 

Attachments

  • error.JPG
    error.JPG
    37.4 KB · Views: 4
  • Capture.JPG
    Capture.JPG
    12.7 KB · Views: 5
Upvote 0
try this change

VBA Code:
For Each ctrl In Me.Frame161.Controls
    
    Select Case TypeName(ctrl)
        
        Case "TextBox", "ComboBox"
            
            If ctrl.Visible Then
                
                If Not EntryRequired Then
                    
                    EntryRequired = CBool(Len(ctrl.Text) = 0)
                    
                    If EntryRequired Then ctrl.SetFocus
                    
                    ctrl.BackColor = IIf(Len(ctrl.Text) = 0, &HC0C0FF, vbWhite)
                End If
                
            End If
            
    End Select
    
Next

Dave
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top