adding form sections with VBA

  • Thread starter Thread starter JamesSoar
  • Start date Start date
J

JamesSoar

Hi everyone

I am looking for a way to add sections to a form through VBA or at
least to check which sections are on.

Help will be greatly appreciated and may be champaign will spark
because I am having a headache with that story !

James Soar
 
James,

To determine which sections are present in a form (or report),
you could just walk the sections "collection" - or pseudo-collection.

const max_sects = 5 ' form: detail, form hdr/ftr, page hdr/ftr
' const max_sects = 5 + 2 * 5 ' or whatever max you like, for reports
Dim i%, Sect as Section
For i = 0 to max_sects - 1
On Error Resume Next
Set Sect = Frm.Sections(i)
If Err <> 0 Then Debug.Print "Section " & Cstr(i) & " is not
present"
Next i

To dynamically create a form's section(s) - which I have not tried from
code - I think you would use something like:
DoCmd.RunCommand acCmdFormHdrFtr
DoCmd.RunCommand acCmdPageHdrFtr

Leastwise, I can't recall (or find reference to) a CreateSection command

Good luck,
CD
 
Hi Chadlon

Many thanks for your answer, definitely it helps me tremendously ! I
didn't succeed to add headers and footers with the DoCmd but anyway it
seems to be the right track !

Thanks again
James
 
James,

Thought I'd improve my edumacation, so tried the following ...

Sub Test_Form_Build()
Dim Frm As Form
Set Frm = CreateForm
DoCmd.Restore ' set a breakpoint here, then F8 through
DoCmd.RunCommand acCmdFormHdrFtr ' watch what happens
DoCmd.RunCommand acCmdFormHdrFtr
DoCmd.RunCommand acCmdFormHdrFtr
DoCmd.RunCommand acCmdPageHdrFtr
DoCmd.Close , , acSaveNo
End Sub

.... works a charm

CD
 
Chadlon

Access life works like a charm for a wizard !!

No more headache for me and thanks for that
James
:D
 
Back
Top