Create a SubForm on a Tab Control



I would appreciate some help with creating a subform control on a tab
control in a create form function. I can create the tab control using
the CreateControl command, but I am not getting the subform created on
the specific page of the tab control. Here is the relevant code:

Public Function MyCreateForm()
'Test to create form with tabs and subforms
On Error GoTo ErrorPoint

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim frm As Form
Dim ctlLabel As Control
Dim strName, strCtl As String
Dim ctlData As Control
Dim mdl As Module
Dim lngReturn As Long

Set db = CurrentDb
strName = "tblQNosTemp"
Set tdf = db.TableDefs(strName)
' Create the form and set properties
Set frm = CreateForm
'Code removed with form settings

strName = "frm" & Mid$(tdf.Name, 4, 20)

'Create the tab control in the Detail section of the form.
Set ctlData = CreateControl(frm.Name, acTabCtl, acDetail, "")
ctlData.Name = "ctlFormTab"
ctlData = Nothing

'Create the subform on page 1 referred to as Page(0) on the tab
Set ctlData = CreateControl(frm.Name, acSubform, "",
ctlData.Name = "ctlSubFormLSM"
DoCmd.Save , strName
DoCmd.Close acForm, strName, acSaveYes

Exit Function

MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " _
& Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question