Auto closing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tawjaw
    New Member
    • Jan 2008
    • 18

    Auto closing

    Can I make my form close automaticlly after I choose a command button from it
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    Add the following code to the end of you Command Button procedure :
    Code:
    Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)

    Comment

    • tawjaw
      New Member
      • Jan 2008
      • 18

      #3
      Originally posted by NeoPa
      Add the following code to the end of you Command Button procedure :
      Code:
      Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)
      This is my command button name: que_Click
      were should I replace it in the code
      thx for helping

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Are you running a MACRO or CODE?
        Originally posted by tawjaw
        This is my command button name: que_Click
        were should I replace it in the code
        thx for helping

        Comment

        • tawjaw
          New Member
          • Jan 2008
          • 18

          #5
          Originally posted by mshmyob
          Are you running a MACRO or CODE?
          I am running a Code
          I'm making a quiz maker using Access
          I'm putting in switchboard (Open Quiz) so a form will open to ask if I want ANSWERS or QUESTIONS (the report will open)
          I want after pressing one of these buttons to close the form automatically (which ask ANS or Que)

          Comment

          • MindBender77
            New Member
            • Jul 2007
            • 233

            #6
            Originally posted by tawjaw
            I am running a Code
            I'm making a quiz maker using Access
            I'm putting in switchboard (Open Quiz) so a form will open to ask if I want ANSWERS or QUESTIONS (the report will open)
            I want after pressing one of these buttons to close the form automatically (which ask ANS or Que)
            Could you not just put this code into the OnOpen event of the report?
            [CODE=vb]
            DoCmd.Close acForm, "FormName",acSa veNo
            [/CODE]

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Originally posted by tawjaw
              This is my command button name: que_Click
              were should I replace it in the code
              thx for helping
              Post in the code you currently have for your que_Click Command Button, then I can tell you where to put the extra line. Essentially it's as you said - at the end.

              If you post it though I can show you exactly where. Please remember to use the [ CODE ] tags provided of course.

              Comment

              • tawjaw
                New Member
                • Jan 2008
                • 18

                #8
                Originally posted by NeoPa
                Post in the code you currently have for your que_Click Command Button, then I can tell you where to put the extra line. Essentially it's as you said - at the end.

                If you post it though I can show you exactly where. Please remember to use the [ CODE ] tags provided of course.
                The code for que_Click is
                Code:
                 Private Sub que_Click()
                On Error GoTo Err_que_Click
                
                    Dim stDocName As String
                
                    stDocName = "Questions"
                    DoCmd.OpenReport stDocName, acPreview
                
                Exit_que_Click:
                    Exit Sub
                
                Err_que_Click:
                    MsgBox Err.Description
                    Resume Exit_que_Click
                    
                End Sub
                The form name is: Quiz

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  You need it after line #7 then :
                  Code:
                  Private Sub que_Click()
                  On Error GoTo Err_que_Click
                  
                      Dim stDocName As String
                  
                      stDocName = "Questions"
                      DoCmd.OpenReport stDocName, acPreview
                      Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)
                  
                  Exit_que_Click:
                      Exit Sub
                  
                  Err_que_Click:
                      MsgBox Err.Description
                      Resume Exit_que_Click
                      
                  End Sub
                  It would need to be in a similar place for the other Command Button too.

                  Comment

                  • tawjaw
                    New Member
                    • Jan 2008
                    • 18

                    #10
                    Originally posted by NeoPa
                    You need it after line #7 then :
                    Code:
                    Private Sub que_Click()
                    On Error GoTo Err_que_Click
                    
                        Dim stDocName As String
                    
                        stDocName = "Questions"
                        DoCmd.OpenReport stDocName, acPreview
                        Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)
                    
                    Exit_que_Click:
                        Exit Sub
                    
                    Err_que_Click:
                        MsgBox Err.Description
                        Resume Exit_que_Click
                        
                    End Sub
                    It would need to be in a similar place for the other Command Button too.
                    Thanks a lot it worked.
                    I'm still new with Access and I never learned Visual Basic language
                    However I'm still 14

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32656

                      #11
                      14's a good age to be learning all this stuff :)

                      I'm glad that helped.

                      Comment

                      Working...