Add Or Remove Form Headers
acCmdDesignView, acCmdFormHdrFtr, acCmdFormView, acCmdSave, acCmdSizeToFitForm
This routine accepts the name of an open form, adds a header and footer if not present or removes them if already present. It then saves and resizes the form.
' ***************** Code Start *************************
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
Sub AddRemoveHeaderFooter(strName As String)
On Error GoTo ErrAddRemove
Application.Echo False
DoCmd.SelectObject acForm, strName, False
DoCmd.RunCommand acCmdDesignView
DoCmd.RunCommand acCmdFormHdrFtr
DoCmd.RunCommand acCmdSave
DoCmd.RunCommand acCmdFormView
DoCmd.RunCommand acCmdSizeToFitForm
Application.Echo True
Exit Sub
ErrAddRemove:
Application.Echo True
Select Case Err
Case 2046
'Command not available
MsgBox "Unable to complete the operation at this time.", vbCritical, "Not Available"
Case 2489
'Object is not open
MsgBox strName & " must be open.", vbCritical, "Object Closed"
Case 2501
'Cancel selected in dialog box - do nothing
Case 2544
'Object does not exist
MsgBox strName & " is not a valid name.", vbCritical, "Naming Error"
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
End Select
End Sub
' *************************** Code End ************************************