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 ************************* ' Example by Terry Wickenden 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 Avialable" 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 ************************************
Return to Example List