Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Create an error log

Posted on 2001-06-14
17
Medium Priority
?
173 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Lucree
  • 11
  • 4
  • 2
17 Comments
 
LVL 4

Accepted Solution

by:
beckingh earned 400 total points
ID: 6192328
Option Explicit

Private Sub Command1_Click()
    Dim Ctrl As Variant
    For Each Ctrl In Controls
        If TypeOf Ctrl Is TextBox Then
            If Ctrl.Text = "" Then
                MsgBox "Control Name: " & Ctrl.Name & " is empty"
            End If
        End If
    Next
End Sub
0
 

Author Comment

by:Lucree
ID: 6192392
it is not finding the textboxes for some reason!
0
 

Author Comment

by:Lucree
ID: 6192398
it is not finding the textboxes for some reason!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:beckingh
ID: 6192419
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
0
 

Author Comment

by:Lucree
ID: 6192445
it is not finding the textboxes for some reason!
0
 

Author Comment

by:Lucree
ID: 6192451
it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
0
 

Author Comment

by:Lucree
ID: 6192471
it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
0
 

Author Comment

by:Lucree
ID: 6192485
it is not having any trouble looping through the controls, just not finding a textbox. so nothing happens.
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6192491
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.



0
 
LVL 2

Expert Comment

by:chandukb
ID: 6192495

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
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6192499
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.



0
 

Author Comment

by:Lucree
ID: 6192570
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!
0
 
LVL 2

Expert Comment

by:chandukb
ID: 6192579
In Excel, you mean u have a form in excel with text boxes.

please provide more info.

Chandu
0
 

Author Comment

by:Lucree
ID: 6192595
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.
0
 

Author Comment

by:Lucree
ID: 6192614
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.
0
 

Author Comment

by:Lucree
ID: 6192671
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.
0
 

Author Comment

by:Lucree
ID: 6192968
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question