Link to home
Start Free TrialLog in
Avatar of Lucree
Lucree

asked on

Create an error log

I am iterested in creating a log of all empty text boxes on several different forms.  I want it to run through and check to make sure each box is field in and if not put it in a log.  I know that I could make a check for each textbox, but is there anyway to do a run through to search all textboxes without calling each text box by its name?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of beckingh
beckingh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lucree
Lucree

ASKER

it is not finding the textboxes for some reason!
Avatar of Lucree

ASKER

it is not finding the textboxes for some reason!
Where are you calling the loop from?  If it is outside of a form you will need to qualify controls with the name of the form...

i.e. if your form name is Form1

   For Each Ctrl In Form1.Controls
Avatar of Lucree

ASKER

it is not finding the textboxes for some reason!
Avatar of Lucree

ASKER

it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
Avatar of Lucree

ASKER

it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
Avatar of Lucree

ASKER

it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
Go to the properties window for one of your forms.  Drop down the listbox right below "Properties - FormName" and see what the type of your "textboxes" are.  They may actually be MaskedBox or something else.

The other option is to try to look at all the controls and if they have a Text property, check if it is = "".

But if you just want to check textboxes this is the best way.




Try diclaring Ctrl as Control

Dim Ctrl As Control

   For Each Ctrl In Me.Controls  'Me is the current form
       If TypeOf Ctrl Is TextBox Then
           If Ctrl.Text = "" Then
               MsgBox "Control Name: " & Ctrl.Name &
                        " is empty"
           End If
       End If
   Next

Chandu
Go to the properties window for one of your forms.  Drop down the listbox right below "Properties - FormName" and see what the type of your "textboxes" are.  They may actually be MaskedBox or something else.

The other option is to try to look at all the controls and if they have a Text property, check if it is = "".

But if you just want to check textboxes this is the best way.



Avatar of Lucree

ASKER

I am actually trying to do it in Excel.  I cant get it to reconize a type for some reason.  I tried it in VB and it works fine.  Trying to get it to work in Excel now!
In Excel, you mean u have a form in excel with text boxes.

please provide more info.

Chandu
Avatar of Lucree

ASKER

yes a from in excel.  what it is doing is. It will count the number of controls and do the loop that many times, but it will not cycle through each control for some reason! So if I have 38 controls on 1 form it will do the loop 38 times stuck on the userform.
Avatar of Lucree

ASKER

yes a from in excel.  what it is doing is. It will count the number of controls and do the loop that many times, but it will not cycle through each control for some reason! So if I have 38 controls on 1 form it will do the loop 38 times stuck on the userform.
Avatar of Lucree

ASKER

I mean a Form not a from.  A form inside of an excel program.  I am sorry about the double posts.  I have been hitting the refresh button and everytime I press it send the message again.
Avatar of Lucree

ASKER

I set the Ctrl equal to an object and placed the object into a TypeName().



Dim AButton As Object
Dim Ctrl As Control

  For Each Ctrl In Controls
     Set AButton = Ctrl
     MsgBox "you clicked on me. I am a " & TypeName(AButton)
  Next

Thanks