Code Examples For RunCommand Constants

Close Open Form

acCmdClose

This example accepts the name of a form and closes it if it is open.

' ****************** Code Start *********************
' Example by Terry Wickenden

Sub CloseOpenForm (strName as String)

  On Error Goto ErrClose

  DoCmd.SelectObject acForm, strName, False
  DoCmd.RunCommand acCmdClose
  Exit Sub

ErrClose:

  Select Case Err
    Case 2489
      'Form Not Open
    Case Else
      MsgBox Err & :-" & vbCrLf & Err.Desciption
  End Select

End Sub

' **************** Code End ******************