Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    Belfast, Ireland
    Posts
    339
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Close another Open Form (2003 SP1)

    I have a Form that I need to open in order for a Link Criteria to work on another Form. However, after opening this Form (Form 1), which then allows the other Form to Open (Form 2), I would like to close Form 1. Nevertheless, I can't get Access to close the Form?!

    Private Sub cmd_Open_Risk_Form_Click()
    On Error GoTo Err_cmd_Open_Risk_Form_Click

    Dim stDocName As String
    Dim stDocName1 As String
    Dim stLinkCriteria As String
    Dim stLinkCriteria1 As String

    stDocName = "R Form"
    stDocName1 = "C Form"

    stLinkCriteria1 = "[company_id]=" & Me![company_id]
    DoCmd.OpenForm stDocName1, , , stLinkCriteria1
    stLinkCriteria = "[company_id]=" & Me![company_id]
    DoCmd.OpenForm stDocName, , , stLinkCriteria


    I have tried using
    DoCmd.Close "C Form"
    DoCmd.Close "stDocName1"
    DoCmd.Close [C Form],,
    DoCmd.Close [stDocName1]

    stDocName1.close

    etc, etc

    I keep getting error messages.

    Obviously, closing a Form in Access is more difficult than one expects!

    Any idea how I can Close Form 1?

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close another Open Form (2003 SP1)

    If you look up the Close method in the VBA help, you'll see that its syntax is

    DoCmd.Close objecttype, objectname, saveas

    The first argument specifies whether you want to close a form or report or whatever. So try

    DoCmd.Close acForm, stDocName1, acSaveNo

    or

    DoCmd.Close acForm, "C Form", acSaveNo

    Note that there are no quotes around stDocName1, for if there are, stDocName is not seen as a variable but as the literal name of the form.

  3. #3
    Star Lounger
    Join Date
    Mar 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close another Open Form (2003 SP1)

    Thanks Hans. I did look up the VBA Help, and that's where I got the syntax I posted here from, but it wasn't working?

    I guess I made a typo or was putting quotes or brackets around the the argument.

    Will try again on Thursday to see how I go.

    Thanks again. [img]/forums/images/smilies/smile.gif[/img]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •