Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2002
    Posts
    23

    Smile Unanswered: How do I close a form with a command button?

    Hi all,

    I have a form with a command button that when clicked, take me to a different form. I also want the first form to close after I click this button. How to I do this?

    Thanks,
    Johnny

  2. #2
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    DoCmd.Close acForm, Me.Name

  3. #3
    Join Date
    Oct 2002
    Posts
    23
    Originally posted by Rockey
    DoCmd.Close acForm, Me.Name
    Thanks Rockey,

    I'm not familiar with VBA, so could you please specify where I put this?

    Thanks,
    Johnny

  4. #4
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    Did you create the command button through the use of a wizard?

  5. #5
    Join Date
    Oct 2002
    Posts
    23
    Originally posted by Rockey
    Did you create the command button through the use of a wizard?
    yes created the button with a wizard.

    Johnny

  6. #6
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    Right click on the button and select Build Event

    You will see code like this:

    Private Sub Command16_Click()
    On Error GoTo Err_Command16_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "FormName"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    DoCmd.Close acForm, Me.Name

    Exit_Command16_Click:
    Exit Sub

    Err_Command16_Click:
    MsgBox Err.Description
    Resume Exit_Command16_Click

    End Sub


    Put it after the line "DoCmd.OpenForm stDocName, , , stLinkCriteria", as shown above.

    Matt

  7. #7
    Join Date
    Oct 2002
    Posts
    23
    Originally posted by Rockey
    Right click on the button and select Build Event

    You will see code like this:

    Private Sub Command16_Click()
    On Error GoTo Err_Command16_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "FormName"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    DoCmd.Close acForm, Me.Name

    Exit_Command16_Click:
    Exit Sub

    Err_Command16_Click:
    MsgBox Err.Description
    Resume Exit_Command16_Click

    End Sub


    Put it after the line "DoCmd.OpenForm stDocName, , , stLinkCriteria", as shown above.

    Matt
    Great! It works. Hey, could you recommend a VBA book? I would like to learn this stuff.

    Thanks again,
    John

  8. #8
    Join Date
    Oct 2002
    Location
    Rochester, NY
    Posts
    84
    Originally posted by MountJohnny
    Great! It works. Hey, could you recommend a VBA book? I would like to learn this stuff.

    Thanks again,
    John
    I can suggest two
    Access 2000 Developer's Handbook (2 volumes) by Getz, Litwin, and Gilbert, Sybex
    Mastering Access 2000 Development by Balter, SAMS
    Regards,
    Terry

Posting Permissions

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