Search Tools Links Login

_An Example of the TypeOf method


I had several forms with several controls on each. I wanted to clear each control, but I wanted to make it as painless as possible. This code takes a form and iterates through each control clearing the values. Currently, it works with text boxes, combo boxes, data pickers, and masked edit controls. all you have to do is pass a form name to the procedure. It uses the for each...next loop, along with the typeof method. I hope this helps.

Original Author: Elliot McCardle

Inputs

for name

Code

Public Sub ClearForm(frm As Form) 'Pass a form name to it
Dim sMask As String
For Each Control In frm.Controls
  If TypeOf Control Is TextBox Or TypeOf Control Is ComboBox Then
   Control.Text = "" 'Clear text
  End If
  If TypeOf Control Is MaskEdBox Then
   With Control
    sMask = .Mask 'Save the existing mask
    .Mask = "" 'Clear mask
    .Text = "" 'Clear text
    .Mask = sMask 'Reset mask
   End With
  End If
  If TypeOf Control Is DTPicker Then
   Control.Date = Date 'Set to current date
  End If
Next Control
End Sub

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 103 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.