Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Standardlösungen > Alle Textfelder leeren (For Each ...)

Alle Textfelder leeren (For Each ...)

Problemstellung Sie möchten alle Textfelder eines Formulars leeren.

Lösung Wenn Sie ein Dutzend Textfelder in Ihrem Formular haben und alle Inhalte daraus entfernen wollen, brauchen Sie nicht entsprechend viele einzelne Codezeilen zu schreiben. Für diese Operation gibt es eine sehr elegante Abkürzung.

Dim ctl As Control
For Each ctl In Me.Controls
   If TypeName(ctl) = "TextBox" Then ctl.Value = ""
Next ctl

Hinweis

Mit einer ähnlichen Konstruktion können Sie auch alle gerade geöffneten Formulare durchgehen:

Dim frm As Form
For Each frm In Forms
   ...
Next frm

Alle Formulare – egal ob gerade geöffnet oder nicht – bezeichnet man übrigens mit AllForms. Der Code sieht dann allerdings etwas anders aus:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial