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
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