R
RobGMiller
Access 2003,
Pages or tabs are added to an existing Tab Control on an existing using VBA.
The initial tab control contains a variable number of pages or tabs. Each
page has a single subform control. The number of added pages is based on a
variable length list. The form containing the tab control is opened in design
mode, the existing tabs\pages are removed except for the first one which is
renamed and then the other tabs\pages are added along with a subform control
on each. The crash occurs when the form is saved and closed from design
mode. The application has to be restarted.
Note: If this is all done manually, there is no problem operating the form.
The error only occurs when the form controls are created programmatically.
The following is the code I used with shortened names.
DoCmd.OpenForm "FormName", acDesign, , , acFormEdit, acHidden
Set Frm = Forms!FormName.Form
Set TabCtl = Frm!TabContainer
For TabCount = 0 To TabCtl.Pages.Count - 1
If TabCount <> 0 Then TabCtl.Pages.Remove
Next TabCount
SQ = "Select * From ListOfTabs Order By SequenceNo;"
Set RS = New ADODB.Recordset
RS.Open SQ, dbconn, adOpenStatic
If Not RS.EOF Then
RS.MoveLast
TotalTabs = RS.RecordCount
FixedWidth = (TabCtl.Properties("Width") - 500) / TotalTabs
'(500 leaves a space between the last tab and the right edge of the
tab control)
RS.MoveFirst
End If
TabCtl.TabFixedWidth = FixedWidth
Frm!TabContainer.Pages(0).Caption = RS!TabName
RS.MoveNext
TabCount = 1
While Not RS.EOF
TabCtl.Pages.Add
TabCtl.Pages(TabCount).Caption = RS!TabName
TabCtl.Pages(TabCount).Name = "P" & TabCount + 1
Set Ctl = CreateControl(Frm.Name, acSubform, acDetail,
TabCtl.Pages(TabCount).Name, , Left, Top, Width, Height)
Set Ctl = Nothing
TabCtl.Pages(TabCount).Controls(0).Name = "P" & TabCount + 1 &
"SFContainer"
TabCtl.Pages(TabCount).Controls(0).SpecialEffect = 0
TabCtl.Pages(TabCount).Controls(0).LinkChildFields = "FileNumber"
TabCtl.Pages(TabCount).Controls(0).LinkMasterFields = "FileNumber"
RS.MoveNext
TabCount = TabCount + 1
Wend
Set TabCtl = Nothing
Set Frm = Nothing
RS.Close
dbconn.Close
DoCmd.Close acForm, "FormName", acSaveYes
Is there anything wrong with the technique used to perform this operation?
Any thoughts or suggestions would be appreciated.
Pages or tabs are added to an existing Tab Control on an existing using VBA.
The initial tab control contains a variable number of pages or tabs. Each
page has a single subform control. The number of added pages is based on a
variable length list. The form containing the tab control is opened in design
mode, the existing tabs\pages are removed except for the first one which is
renamed and then the other tabs\pages are added along with a subform control
on each. The crash occurs when the form is saved and closed from design
mode. The application has to be restarted.
Note: If this is all done manually, there is no problem operating the form.
The error only occurs when the form controls are created programmatically.
The following is the code I used with shortened names.
DoCmd.OpenForm "FormName", acDesign, , , acFormEdit, acHidden
Set Frm = Forms!FormName.Form
Set TabCtl = Frm!TabContainer
For TabCount = 0 To TabCtl.Pages.Count - 1
If TabCount <> 0 Then TabCtl.Pages.Remove
Next TabCount
SQ = "Select * From ListOfTabs Order By SequenceNo;"
Set RS = New ADODB.Recordset
RS.Open SQ, dbconn, adOpenStatic
If Not RS.EOF Then
RS.MoveLast
TotalTabs = RS.RecordCount
FixedWidth = (TabCtl.Properties("Width") - 500) / TotalTabs
'(500 leaves a space between the last tab and the right edge of the
tab control)
RS.MoveFirst
End If
TabCtl.TabFixedWidth = FixedWidth
Frm!TabContainer.Pages(0).Caption = RS!TabName
RS.MoveNext
TabCount = 1
While Not RS.EOF
TabCtl.Pages.Add
TabCtl.Pages(TabCount).Caption = RS!TabName
TabCtl.Pages(TabCount).Name = "P" & TabCount + 1
Set Ctl = CreateControl(Frm.Name, acSubform, acDetail,
TabCtl.Pages(TabCount).Name, , Left, Top, Width, Height)
Set Ctl = Nothing
TabCtl.Pages(TabCount).Controls(0).Name = "P" & TabCount + 1 &
"SFContainer"
TabCtl.Pages(TabCount).Controls(0).SpecialEffect = 0
TabCtl.Pages(TabCount).Controls(0).LinkChildFields = "FileNumber"
TabCtl.Pages(TabCount).Controls(0).LinkMasterFields = "FileNumber"
RS.MoveNext
TabCount = TabCount + 1
Wend
Set TabCtl = Nothing
Set Frm = Nothing
RS.Close
dbconn.Close
DoCmd.Close acForm, "FormName", acSaveYes
Is there anything wrong with the technique used to perform this operation?
Any thoughts or suggestions would be appreciated.