Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Location
    Manchester, NH
    Posts
    57

    Question Unanswered: How do i close a second form from same close button

    I have a cancel button that closes its form right now, but i want it to close another form that is open also, how?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    open your form then menu: View¦DesignView then menu:View¦Code

    locate the form-close code that already exists (if there is lots of code, Find "DoCmd.Close")

    you will see a line:
    DoCmd.Close acForm "name of the form"
    -or-
    DoCmd.Close acForm StrDocName
    depending how the original Close was built.

    simply insert another line immediately above the existing one:
    DoCmd.Close acForm "nameOfAnotherForm"

    ...or any number of lines
    DoCmd.Close acForm "nameOfAnyOpenForm"
    DoCmd.Close acForm "nameOfYetAnotherForm"
    etc


    izy

  3. #3
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: How do i close a second form from same close button

    Try this :

    I put a button (named cancelButton) on Form1


    Private Sub cancelButton_Click()
    DoCmd.Close acForm, Form_Form1.Name, acSaveNo
    DoCmd.Close acForm, Form_Form2.Name, acSaveNo
    End Sub

  4. #4
    Join Date
    Apr 2003
    Location
    Manchester, NH
    Posts
    57

    OK but i get a compile error!

    when i use:

    DoCmd.Close acForm "lookup_help"

    I get a compile error, so do i need to enter more parameters or something?


    Originally posted by izyrider
    open your form then menu: View¦DesignView then menu:View¦Code

    locate the form-close code that already exists (if there is lots of code, Find "DoCmd.Close")

    you will see a line:
    DoCmd.Close acForm "name of the form"
    -or-
    DoCmd.Close acForm StrDocName
    depending how the original Close was built.

    simply insert another line immediately above the existing one:
    DoCmd.Close acForm "nameOfAnotherForm"

    ...or any number of lines
    DoCmd.Close acForm "nameOfAnyOpenForm"
    DoCmd.Close acForm "nameOfYetAnotherForm"
    etc


    izy

  5. #5
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: OK but i get a compile error!

    Originally posted by dalynching
    when i use:

    DoCmd.Close acForm "lookup_help"

    I get a compile error, so do i need to enter more parameters or something?
    Just be sure 'lookup_help' is the name of the form you want to close.
    Put a comma between acForm and "lookup_help".

  6. #6
    Join Date
    Apr 2003
    Location
    Manchester, NH
    Posts
    57

    Excellent, that works great!

    Thanks for all the help, that worked great!

    Originally posted by artemide
    Just be sure 'lookup_help' is the name of the form you want to close.
    Put a comma between acForm and "lookup_help".

  7. #7
    Join Date
    Apr 2003
    Location
    Manchester, NH
    Posts
    57

    oh 1 more thing about printing...

    I need to print a second form from the 1st form print button, any help on that please?

    Originally posted by dalynching
    Thanks for all the help, that worked great!

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    1st: apologies for the missing "," (thanks artemide for the correction)

    2nd: follow the same principle: if you've already got a print-form that works, find it in the code window and add another line. mr gates is very fond of DIMming strings and then using the variable (the famous StrDocName) but as you saw with .Close a direct "nameAsQuotedString" works just as well. copy the existing line and replace StrDocName with the name of your form in quotes.

    ...but don't forget the "," ;-)

    izy

Posting Permissions

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