Find Type of Control In A Form

mlai08

Registered User.
Local time
Today, 05:57
Joined
Dec 20, 2007
Messages
110
I am trying to loop through all controls in a form and do something when a specific type of control is found. However, the control type is not a supported property. I did try to search the forum but without avail. I wrote the following codes which do not work. Hope someone can give me a hint.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim Crtl As Control

For Each Crtl In Me.Controls
If Crtl.type = "textbox" Then
MsgBox "Text box found."
Cancel = True
Exit Sub
End If
Next

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description, vbCritical
Resume Exit_Form_BeforeUpdate
End Sub

Thanks

Mike :confused:
 
Easy solution would be to use a naming convention for your controls as well as your forms/queries/tables etc.

In this case all textboxes would be called txt... and name is an object you can fetch :)

Good luck
 
Thanks for the suggestion. I finally figured it out.

if Crtl.ControlType = acTextbox then
do something
end if

Easy solution would be to use a naming convention for your controls as well as your forms/queries/tables etc.

In this case all textboxes would be called txt... and name is an object you can fetch :)

Good luck
 
YOU CAN find the type of a control directly

its the CONTROLTYPE property of the PROPERTIES collection of a control

ie ctrl.properties.controltype

------
look at create control help for the different constants defining the control type

[edit - read the thread again - i see you got it already]
 

Users who are viewing this thread

Back
Top Bottom