Results 1 to 5 of 5
  1. #1
    ghostmachine is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    4

    Closing a form through VBA

    hi


    i am having a little trouble getting my VBA code to work for closing a form.

    I have create a form, and a command button called "Close". here's the simple code,

    Code:
    Sub cmdClose_Click()
         globalFormName = Me.Name
         Call myCloseForm(globalFormName)
    End Sub
    in VB editor, I created a Module1, and included a subroutine like this:

    Code:
    Public globalFormName As String
    
    Public Sub myCloseForm(ByVal strName As String)
            DoCmd.Close acForm, strName
    End Sub
    Then I try to view the form in Form view and click the button. But nothing happens. What could be the problem?
    thanks

  2. #2
    ansentry's Avatar
    ansentry is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    67
    Try this code behind you cmdClose button:


    Code:
    Sub cmdClose_Click()
         DoCmd.Close acForm, Me.Name
    End Sub

  3. #3
    ghostmachine is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    4
    Quote Originally Posted by ansentry View Post
    Try this code behind you cmdClose button:


    Code:
    Sub cmdClose_Click()
         DoCmd.Close acForm, Me.Name
    End Sub
    hi, thanks for replying. i can't even do a simple Msgbox test, let alone close the form

    Code:
    Sub cmdClose_Click()
         MsgBox("Test")
    End Sub
    the msgbox doesn't show up.

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you button client event is not link to you procedure "cmdClose_Click".
    you can try to right cliek on the button in form design view, the select Event on the popup menu, this will lead you to the click event procedure of this button or build up the link to an existing procedure.

    then try again.

  5. #5
    SteveH2508 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Is your database in a Trusted Location?

    If it is not your code will not run.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 AM
  2. Prevent a form from closing
    By ksmithson in forum Forms
    Replies: 0
    Last Post: 07-15-2010, 12:49 PM
  3. Replies: 1
    Last Post: 06-25-2010, 09:56 AM
  4. Closing a Form Problem
    By MuskokaMad in forum Forms
    Replies: 2
    Last Post: 03-18-2010, 05:58 AM
  5. Replies: 2
    Last Post: 03-14-2010, 08:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums