Results 1 to 10 of 10

Thread: DoCmd.Close problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    DoCmd.Close problem

    Hello,
    I am just starting to learn VBA (have a bit of experience in VB.net), and am having problems right off the bat. Currently, I have created a user form with a single button whose sole purpose is to close the form. The code to do this is as follows:
    Code:
    Private Sub CBClose_Click()
    
        DoCmd.Close acForm, Me.Name
    
    End Sub
    This is the entirety of the code so far. Now, when I click the button to close the form, I receive an error stating "Object Required" (debug points to the DoCmd.Close line). After googling the problem, every other occurrence I found had to do with something not applicable to my current problem. Does anyone have any ideas as to why this is happening?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: DoCmd.Close problem

    vb Code:
    1. Private Sub CBClose_Click()
    2.  
    3.     Unload acForm
    4.  
    5. End Sub

    (Assuming acForm is the form name)

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: DoCmd.Close problem

    Using the code you provided (modified to reflect the actual form name), I now receive a "Can't load or unload this object" error

  4. #4
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: DoCmd.Close problem

    Is CBClose the name of a command button on the form?

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: DoCmd.Close problem

    Yes.

  6. #6
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: DoCmd.Close problem

    Can you post the file?

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: DoCmd.Close problem

    Attached.
    Attached Files Attached Files

  8. #8
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: DoCmd.Close problem

    The should be exactly like this... (you had parenthesis around the form name)

    vb Code:
    1. Private Sub CBClose_Click()
    2.  
    3.     Unload UserForm1
    4.  
    5. End Sub

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: DoCmd.Close problem

    Thanks, that worked. I was thrown off by the intellisense.

  10. #10
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: DoCmd.Close problem

    You could also use:
    vb Code:
    1. Private Sub CBClose_Click()
    2.     Unload Me
    3. End Sub
    This way, you don't have to edit the code if you change the name of the form, or use the code in a different form.

Posting Permissions

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



Click Here to Expand Forum to Full Width