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.
Inputs
for name
Rate An Example of the TypeOf method
(6(6 Vote))
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
An Example of the TypeOf method Comments
No comments yet — be the first to post one!
Post a Comment