Solved

Create an error log

Posted on 2001-06-14
17
162 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now