Solved

Create an error log

Posted on 2001-06-14
17
166 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 100 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 42
Macro Excel - Multiple If conditions 2 87
Formula problem with Excel attachment 6 43
Set WorkSheet  not Working 9 51
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

756 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