Determine the section of a control

Bent2Bits

Registered User.
Local time
Tomorrow, 07:00
Joined
Aug 31, 2012
Messages
16
Hi all,

I am attempting to add a rectagle around all of my user controls on all of my forms through vba. I have succeeded in doing this with the exception of controls that are in my footer. These controls are getting their rectangles drawn in the Detail section. Is there a way to return the section of a control while cycling through them so that is can be added to the CreateControl method?

Thank you for any assistance you can provide!
Below is the code I have written to get where I am:

Dim objAccFrm As AccessObject
Dim objTest As Object
Dim ctrl As Control
Dim rectangle As Control
Dim strTop, strLeft, strHeight, strWidth As String
Dim boxnum As Integer
Dim Boxname As String
Dim frm As String
Dim currentform As Form

Set objTest = Application.CurrentProject
boxnum = 1


For Each objAccFrm In objTest.AllForms
frm = objAccFrm.name
'If frm = "frmstatusreporting1" Then (***testing a single form***)
DoCmd.OpenForm frm, acDesign
Set currentform = Application.Screen.activeform
For Each ctrl In currentform.Controls
Debug.Print ctrl.name
If ctrl.ControlType = ctrl.ControlType = acTextBox Or _
ctrl.ControlType = acOptionButton Or ctrl.ControlType = acComboBox Or _
ctrl.ControlType = acCheckBox Or ctrl.ControlType = acCommandButton Then
If ctrl.Visible = True Then
Boxname = "ctrBox_" + CStr(boxnum)
strTop = ctrl.Top
strLeft = ctrl.Left
strHeight = ctrl.Height
strWidth = ctrl.Width
Set rectangle = CreateControl(frm, acRectangle, , , , strLeft, strTop, strWidth, strHeight)
rectangle.Visible = False
rectangle.name = Boxname
rectangle.BorderStyle = 1
rectangle.BorderWidth = 1
rectangle.BorderColor = vbBlack
rectangle.SpecialEffect = 0
boxnum = boxnum + 1
End If
End If
Next ctrl

DoCmd.Close acForm, frm, acSave
'End If
Set ctrl = Nothing
boxnum = 1

Next objAccFrm
 
maybe you can iterate the sections, and controls within sections. not checked to see though

this sort of thing

Code:
for each section in frm.sections
     for each ctrl in section.controls
     next
next
 
Hey Gemma,

I was unable to cycle through the sections, however you inspired a different way to reach the same result.

If ctrl.Section = 0 Then
Set rectangle = CreateControl(frm, acRectangle, , , , strLeft, strTop, strWidth, strHeight)
Elseif ctrl.Section = 1 then
Set rectangle = CreateControl(frm, acRectangle, acFooter, , , strLeft, strTop, strWidth, strHeight)
End If

Thanks for pointing me in the right direction.
Bent
 
glad you got a fix.

I wasn't sure whether sections were containers for controls. clearly the section is a property of the control, rather than the other way round.
 

Users who are viewing this thread

Back
Top Bottom