button i subform who close only the subform and not all forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ubrukelig
    New Member
    • Dec 2016
    • 14

    button i subform who close only the subform and not all forms

    I have a mainform called STV_Feilsak and a subform called PCSak. I use Access 2013. and vba access.

    I have tried to make a button who close the subform, but close all forms. need to close only subform.

    I have tried diffrent code, but all fails. CLOSE button code are in PCSak form.

    How to solve this?

    Whats wrong? I tried different codes, but it fails. None of these are right or not in right place. examples under.

    Code:
    Me.Parent.PCSak.Visible = False
    Code:
    Me![PCSak].Visible = False
    Code:
    Me.Parent.STV_Feilsak.SetFocus
    Me.Parent.PCSak.Visible = False
    Code:
    Forms!Form_STV_Feilsak.ControlOnMainForm.SetFocus
    Forms!PCSak.SubformControlName.Visible = False
    Code:
    Me![STV_Feilsak].SetFocus
    Code:
    Me![STV_Feilsak]!SetFocus
    Me.Visible = False
    Last edited by zmbd; Jan 22 '17, 08:55 PM. Reason: [z{merged related posts}{added code format}]
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    I'm not sure what you are attempting to do. I'm guessing you are attempting to click a Button and Hide a SubForm.

    Setting any Control's Visible or Enabled property to False while the Control has Focus tends to cause an error. If you want to set a SubForm's visibility to False, you should do it from the MainForm so that the SubForm doesn't have Focus.

    If you were to create a Button on the MainForm and put something like this in the OnClick event, it will Toggle the Visibility of the Form:
    Code:
    Me.PCSak.Visible = Not Me.PCSak.Visible

    Comment

    • Ubrukelig
      New Member
      • Dec 2016
      • 14

      #3
      Hello, what i am trying to do is : I have a mainform and a subform who looks lika a popup when it shows up. In the Subform i have a button named CLOSE. How to make it works? Its easy if i use a button i mainform, but i want it to work in subform.

      In the picure you can see what i mean. The button who says "Lukke skjema" Means close subform. And if i make it work, then it close both forms. So only subform to close i want.

      [IMGnothumb]https://bytes.com/attachment.php? attachmentid=90 05[/IMGnothumb]
      Attached Files
      Last edited by zmbd; Jan 22 '17, 08:58 PM. Reason: [z{merged related posts}{inserted image in merged posts}]

      Comment

      • jforbes
        Recognized Expert Top Contributor
        • Aug 2014
        • 1107

        #4
        You can use the Wizard to create a Close Button for your SubForm. If you were to do so, you would get some code like this for your button:
        Code:
        If Me.Dirty Then Me.Dirty = False
        DoCmd.Close

        Comment

        • Ubrukelig
          New Member
          • Dec 2016
          • 14

          #5
          Hello!
          I dont know how to use me.dirty code. How should the code be??
          I tried wizard, but it use macro, not vba. And when i use macro it close both forms. My problem are still the same. How to close only one form.

          Comment

          • Ubrukelig
            New Member
            • Dec 2016
            • 14

            #6
            Can anyone reply me a code thats work? plz.

            Comment

            Working...