Form Code using me.Controls (1 Viewer)

kirkm

Registered User.
Local time
Today, 12:41
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) ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:41
Joined
May 7, 2009
Messages
19,231
just append the Property:

ctl.Top
ctl.Left
ctl.FontName
ctl.FontSize
...etc.
 

kirkm

Registered User.
Local time
Today, 12:41
Joined
Oct 30, 2008
Messages
1,257
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:41
Joined
May 7, 2009
Messages
19,231
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
 

kirkm

Registered User.
Local time
Today, 12:41
Joined
Oct 30, 2008
Messages
1,257
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

Top Bottom