Dirk,
It works now.
I must have been stepping through it as you suggest.
I moved the:
DoCmd.RunCommand acCmdFormHdrFtr
up to just before the CreateControl for the label.
I had to remove the Parent parameter in the CreateControl
for the label in order for acHeader to put the label in
the Header.
I still have to use:
DoCmd.OpenForm "Form1", , , stLinkCriteria
at the end to open the form as without this statement the
form remains in Design mode.
A funky thing does happen if I try to use the new Caption
name as follows in the OpenForm statement:
DoCmd.OpenForm "frmTest1", , , stLinkCriteria
I get two forms. One entitled frmTest1 and the other
entitled Form1. The one entitled frmTest1 has the label
still in the Detail section while the one entitled Form1
has the label in the Header but is still in Design mode.
It's not a problem, however, as I just use Form1.
The OpenForm statement was generated when I created the
command button. I don't know and can find no indication
of what the WHERE parameter stLinkCriteria is used for.
It appears to be always blank.
Thanks so much for your help. I may be coming back as I
would like to put a command button in the footer to close
the form and I'm not too sure how much help I will get
from the system.
The updated code follows:
--------------------------------
Private Sub cmdCreateControls_Click()
On Error GoTo Err_cmdCreateControls_Click
Dim stDocName As String
Dim stLinkCriteria As String
' NewControls
' *********** Create Controls ***********************
Dim frm As Form
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer
Dim intLabelX As Integer, intLabelY As Integer
' Create new form with Orders table as its record
source.
Set frm = CreateForm()
frm.RecordSource = "Orders" 'imported from Nwind.mdb
' Set positioning values for new controls.
intLabelX = 100
intLabelY = 20
intDataX = 100
intDataY = 20
' Create unbound default-size text box in detail
section.
Set ctlText = CreateControl(frm.Name, acTextBox,
acDetail, "", "", _
intDataX, intDataY)
DoCmd.RunCommand acCmdFormHdrFtr
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel,
acHeader, _
"", "NewLabel", intLabelX, intLabelY)
' Restore form.
DoCmd.Restore
'
***********************************************************
********
frm.text0.ControlSource = "OrderID"
frm.[DefaultView] = 1
frm.Section(0).Height = 1.5
frm.Caption = "frmTest1"
DoCmd.MoveSize , , 7000
DoCmd.OpenForm "Form1", , , stLinkCriteria
' DoCmd.OpenForm "frmTest1", , , stLinkCriteria
Exit_cmdCreateControls_Click:
Exit Sub
Err_cmdCreateControls_Click:
MsgBox Err.Description
Resume Exit_cmdCreateControls_Click
End Sub
I do use the
-----Original Message-----
Doug MacDonald said:
Continuing to work on how to create controls in
the Header of a form, the following is somewhat
of a concern.
The Access Object Browser shows the CreateControl
Method with [Section As AcSection = acDetail]
almost indicating that "acDetail" is the only
valid parameter. The Help file shows a slightly
different format for CreateControl. I have them
both listed below.
***** Object Browser Format ***********
Function CreateControl(FormName As String,
ControlType As AcControlType,
[Section As AcSection = acDetail], [Parent], [ColumnName],
, [Top], [Width], [Height]) As Control
******Help File Format ****************
CreateControl(formname, controltype[,
section[, parent[, columnname[,
left[, top[, width[, height]]]]]]])
**************************************
I have several hours into this "Control in Header"
search effort now. I'm certainly learning a lot but
it sure is frustrating. Thanks for the support.
That format for the parameter specification -- [Section As AcSection =
acDetail] -- simply means that the Section parameter is optional, and if
you don't specify it the Detail section (acDetail) is assumed.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
.