Form Code using me.Controls

kirkm

Registered User.
Local time
Tomorrow, 00:59
Joined
Oct 30, 2008
Messages
1,257
Code:
 For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            If ctl.Name = "txtImport" Then Stop

At this point in the code how do you get the controls properties (like, width, Top, Font etc) ?
 
just append the Property:

ctl.Top
ctl.Left
ctl.FontName
ctl.FontSize
...etc.
 
I could have sworn I'd tried that!
Why are they not in the drop down list (if that's not a silly question) ? That probably made me think they weren't an option.
Although ctl.Top becomes TopPadding. Somewhat puzzling.
 
it's not showing because ctl is declared as Control (general).
since Not all Controls have same Properties, therefore it does not show.

but if you are sure of the correct Type of the control, then you can declare it as such
and its member will show, example

Dim ctl As Control 'general type
Dim tbx As Textbox 'specific type
For Each ctl In Me.Controls
If TypeName(ctl) = "Textbox" Then
Set tbx = ctl
'typing tbx + dot will show you the members (properties)
End If
Next
 
Thanks again arne, you've given me quite a bit of valuable info today. Still playing with your example code (although I could not run it from the BeforeUpdate event). Things were working but have improved it considerably. Not sure how wise (although seemed logical) first check TypeOf ctl Is TextBox then if textbox.tag =1, so limiting it to just the texboxes that are allowed edits. But the big improvement was your .oldValue<> .value. Previously I was comparing a Recordset with the Forms controls.
 

Users who are viewing this thread

Back
Top Bottom