Programatically Delete Command Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Melissa

    #1

    Programatically Delete Command Button

    What is the code to delete a command button from a form? Can the code be run
    from the click event of the button to be deleted?

    Thanks!

    Melissa


  • Rick Brandt

    #2
    Re: Programatically Delete Command Button

    "Melissa" <mkurtz@earthli nk.net> wrote in message
    news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=blue]
    > What is the code to delete a command button from a form? Can the code be[/color]
    run[color=blue]
    > from the click event of the button to be deleted?[/color]

    Do you mean hide it? Why would you ever need (or want) to delete a button
    from code?


    --
    I don't check the Email account attached
    to this message. Send instead to...
    RBrandt at Hunter dot com


    Comment

    • Wayne Morgan

      #3
      Re: Programatically Delete Command Button

      To delete the button, the form has to be in design mode. You can, however,
      hide the button by setting its Visible property to False. You can't do this
      to the control that has the focus, so you'll have to move the focus to
      another control before hiding the button. I just tested it to make sure and,
      yes, you can hide the button in its own click event.

      --
      Wayne Morgan
      Microsoft Access MVP


      "Melissa" <mkurtz@earthli nk.net> wrote in message
      news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=blue]
      > What is the code to delete a command button from a form? Can the code be[/color]
      run[color=blue]
      > from the click event of the button to be deleted?[/color]


      Comment

      • Melissa

        #4
        Re: Programatically Delete Command Button

        I need to run a one-time procedure and I was thinking of running it with a
        self-destrucy button so that the procedure could not be run again!

        Melissa



        "Rick Brandt" <rickbrandt2@ho tmail.com> wrote in message
        news:2hf2n5Fcca v9U1@uni-berlin.de...[color=blue]
        > "Melissa" <mkurtz@earthli nk.net> wrote in message
        > news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=green]
        > > What is the code to delete a command button from a form? Can the code be[/color]
        > run[color=green]
        > > from the click event of the button to be deleted?[/color]
        >
        > Do you mean hide it? Why would you ever need (or want) to delete a button
        > from code?
        >
        >
        > --
        > I don't check the Email account attached
        > to this message. Send instead to...
        > RBrandt at Hunter dot com
        >
        >[/color]


        Comment

        • Melissa

          #5
          Re: Programatically Delete Command Button

          I need to run a one-time procedure and I was thinking of running it with a
          self-destrucy button so that the procedure could not be run again!

          Melissa


          "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
          news:WAssc.3717 $Qz1.1152@newss vr16.news.prodi gy.com...[color=blue]
          > To delete the button, the form has to be in design mode. You can, however,
          > hide the button by setting its Visible property to False. You can't do this
          > to the control that has the focus, so you'll have to move the focus to
          > another control before hiding the button. I just tested it to make sure and,
          > yes, you can hide the button in its own click event.
          >
          > --
          > Wayne Morgan
          > Microsoft Access MVP
          >
          >
          > "Melissa" <mkurtz@earthli nk.net> wrote in message
          > news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=green]
          > > What is the code to delete a command button from a form? Can the code be[/color]
          > run[color=green]
          > > from the click event of the button to be deleted?[/color]
          >
          >[/color]


          Comment

          • Jim Allensworth

            #6
            Re: Programatically Delete Command Button

            Hiding the button does the same as destroying it.

            Since it is a one time thing you might just use a custom database
            property. When the form opens do check of the property and set the
            visibility depending on the value of the property.

            Of course when the procedure is first run - set the property value.

            - Jim

            On Mon, 24 May 2004 20:43:54 GMT, "Melissa" <mkurtz@earthli nk.net>
            wrote:
            [color=blue]
            >I need to run a one-time procedure and I was thinking of running it with a
            >self-destrucy button so that the procedure could not be run again!
            >
            >Melissa
            >
            >
            >"Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
            >news:WAssc.371 7$Qz1.1152@news svr16.news.prod igy.com...[color=green]
            >> To delete the button, the form has to be in design mode. You can, however,
            >> hide the button by setting its Visible property to False. You can't do this
            >> to the control that has the focus, so you'll have to move the focus to
            >> another control before hiding the button. I just tested it to make sure and,
            >> yes, you can hide the button in its own click event.
            >>
            >> --
            >> Wayne Morgan
            >> Microsoft Access MVP
            >>
            >>
            >> "Melissa" <mkurtz@earthli nk.net> wrote in message
            >> news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=darkred]
            >> > What is the code to delete a command button from a form? Can the code be[/color]
            >> run[color=darkred]
            >> > from the click event of the button to be deleted?[/color]
            >>
            >>[/color]
            >
            >[/color]

            Comment

            • Rich P

              #7
              Re: Programatically Delete Command Button

              Well, there is one thing you could do. On the main form, bring up a
              second form which contains the procedure that you want to run just once
              on the form open event. Bring up that form and run your procedure.
              Once the procedure is run, note that in a table somewhere. From you
              main form, check this table to see if the procedure has been run. If
              yes, then loop throught the Containers.Docu ments collection to see if
              this secondary form exists. If yes, do a DoCmd.DeleteObj ect AcForm,
              "YourForm". For Acc2000 you can use the CurrentProject. AllForms
              property instead of Containers and Documents. This is kind of
              redundant, but it is a technique. So instead of eliminating the button,
              you are eliminating the whole form and procedure.

              Rich

              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • WindAndWaves

                #8
                Re: Programatically Delete Command Button

                This is the help from Microsoft, you can access it from the module window by
                typing deletecontrol, selecting it and pressing F1.



                DeleteControl Method

                The DeleteControl method deletes a specified control from a form.

                expression.Dele teControl(FormN ame, ControlName)

                expression Required. An expression that returns one of the objects in the
                Applies To list.

                FormName Required String. A string expression identifying the name of the
                form or report containing the control you want to delete.

                ControlName Required String. A string expression identifying the name of
                the control you want to delete.

                Remarks
                For example, suppose you have a procedure that must be run the first time
                each user logs onto your database. You can set the OnClick property of a
                button on the form to this procedure. Once the user has logged on and run
                the procedure, you can use the DeleteControl method to dynamically remove
                the command button from the form.

                The DeleteControl method is available only in form Design view or report
                Design view, respectively.

                Note If you are building a wizard that deletes a control from a form or
                report, your wizard must open the form or report in Design view before it
                can delete the control.

                Example
                The following example creates a form with a command button and displays a
                message that asks if the user wants to delete the command button. If the
                user clicks Yes, the command button is deleted.

                Sub DeleteCommandBu tton()
                Dim frm As Form, ctlNew As Control
                Dim strMsg As String, intResponse As Integer, _
                intDialog As Integer

                ' Create new form and get pointer to it.
                Set frm = CreateForm
                ' Create new command button.
                Set ctlNew = CreateControl(f rm.Name, acCommandButton )
                ' Restore form.
                DoCmd.Restore
                ' Set caption.
                ctlNew.Caption = "New Command Button"
                ' Size control.
                ctlNew.SizeToFi t
                ' Prompt user to delete control.
                strMsg = "About to delete " & ctlNew.Name &". Continue?"
                ' Define buttons to be displayed in dialog box.
                intDialog = vbYesNo + vbCritical + vbDefaultButton 2
                intResponse = MsgBox(strMsg, intDialog)
                If intResponse = vbYes Then
                ' Delete control.
                DeleteControl frm.Name, ctlNew.Name
                End If
                End Sub
                "Melissa" <mkurtz@earthli nk.net> wrote in message
                news:%7tsc.2485 8$zO3.23939@new sread2.news.atl .earthlink.net. ..[color=blue]
                > I need to run a one-time procedure and I was thinking of running it with a
                > self-destrucy button so that the procedure could not be run again!
                >
                > Melissa
                >
                >
                >
                > "Rick Brandt" <rickbrandt2@ho tmail.com> wrote in message
                > news:2hf2n5Fcca v9U1@uni-berlin.de...[color=green]
                > > "Melissa" <mkurtz@earthli nk.net> wrote in message
                > > news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...[color=darkred]
                > > > What is the code to delete a command button from a form? Can the code[/color][/color][/color]
                be[color=blue][color=green]
                > > run[color=darkred]
                > > > from the click event of the button to be deleted?[/color]
                > >
                > > Do you mean hide it? Why would you ever need (or want) to delete a[/color][/color]
                button[color=blue][color=green]
                > > from code?
                > >
                > >
                > > --
                > > I don't check the Email account attached
                > > to this message. Send instead to...
                > > RBrandt at Hunter dot com
                > >
                > >[/color]
                >
                >[/color]


                ---
                Please immediately let us know (by phone or return email) if (a) this email
                contains a virus
                (b) you are not the intended recipient
                (c) you consider this email to be spam.
                We have done our utmost to make sure that
                none of the above are applicable. THANK YOU
                Checked by AVG anti-virus system (http://www.grisoft.com).
                Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004


                Comment

                • Melissa

                  #9
                  Re: Programatically Delete Command Button

                  I really appreciate you taking the time to offer this suggestion. It is just
                  what I was initially looking for. Rich P offered a suggestion that I am going to
                  try and if I run into any problems with it, it's right back to your suggestion I
                  come!!

                  Thank you.


                  "WindAndWav es" <access@ngaru.c om> wrote in message
                  news:dRvsc.9653 $XI4.347632@new s.xtra.co.nz...[color=blue]
                  > This is the help from Microsoft, you can access it from the module window by
                  > typing deletecontrol, selecting it and pressing F1.
                  >
                  >
                  >
                  > DeleteControl Method
                  >
                  > The DeleteControl method deletes a specified control from a form.
                  >
                  > expression.Dele teControl(FormN ame, ControlName)
                  >
                  > expression Required. An expression that returns one of the objects in the
                  > Applies To list.
                  >
                  > FormName Required String. A string expression identifying the name of the
                  > form or report containing the control you want to delete.
                  >
                  > ControlName Required String. A string expression identifying the name of
                  > the control you want to delete.
                  >
                  > Remarks
                  > For example, suppose you have a procedure that must be run the first time
                  > each user logs onto your database. You can set the OnClick property of a
                  > button on the form to this procedure. Once the user has logged on and run
                  > the procedure, you can use the DeleteControl method to dynamically remove
                  > the command button from the form.
                  >
                  > The DeleteControl method is available only in form Design view or report
                  > Design view, respectively.
                  >
                  > Note If you are building a wizard that deletes a control from a form or
                  > report, your wizard must open the form or report in Design view before it
                  > can delete the control.
                  >
                  > Example
                  > The following example creates a form with a command button and displays a
                  > message that asks if the user wants to delete the command button. If the
                  > user clicks Yes, the command button is deleted.
                  >
                  > Sub DeleteCommandBu tton()
                  > Dim frm As Form, ctlNew As Control
                  > Dim strMsg As String, intResponse As Integer, _
                  > intDialog As Integer
                  >
                  > ' Create new form and get pointer to it.
                  > Set frm = CreateForm
                  > ' Create new command button.
                  > Set ctlNew = CreateControl(f rm.Name, acCommandButton )
                  > ' Restore form.
                  > DoCmd.Restore
                  > ' Set caption.
                  > ctlNew.Caption = "New Command Button"
                  > ' Size control.
                  > ctlNew.SizeToFi t
                  > ' Prompt user to delete control.
                  > strMsg = "About to delete " & ctlNew.Name &". Continue?"
                  > ' Define buttons to be displayed in dialog box.
                  > intDialog = vbYesNo + vbCritical + vbDefaultButton 2
                  > intResponse = MsgBox(strMsg, intDialog)
                  > If intResponse = vbYes Then
                  > ' Delete control.
                  > DeleteControl frm.Name, ctlNew.Name
                  > End If
                  > End Sub
                  > "Melissa" <mkurtz@earthli nk.net> wrote in message
                  > news:%7tsc.2485 8$zO3.23939@new sread2.news.atl .earthlink.net. ..[color=green]
                  > > I need to run a one-time procedure and I was thinking of running it with a
                  > > self-destrucy button so that the procedure could not be run again!
                  > >
                  > > Melissa
                  > >
                  > >
                  > >
                  > > "Rick Brandt" <rickbrandt2@ho tmail.com> wrote in message
                  > > news:2hf2n5Fcca v9U1@uni-berlin.de...[color=darkred]
                  > > > "Melissa" <mkurtz@earthli nk.net> wrote in message
                  > > > news:1Grsc.3154 9$KE6.99@newsre ad3.news.atl.ea rthlink.net...
                  > > > > What is the code to delete a command button from a form? Can the code[/color][/color]
                  > be[color=green][color=darkred]
                  > > > run
                  > > > > from the click event of the button to be deleted?
                  > > >
                  > > > Do you mean hide it? Why would you ever need (or want) to delete a[/color][/color]
                  > button[color=green][color=darkred]
                  > > > from code?
                  > > >
                  > > >
                  > > > --
                  > > > I don't check the Email account attached
                  > > > to this message. Send instead to...
                  > > > RBrandt at Hunter dot com
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >
                  > ---
                  > Please immediately let us know (by phone or return email) if (a) this email
                  > contains a virus
                  > (b) you are not the intended recipient
                  > (c) you consider this email to be spam.
                  > We have done our utmost to make sure that
                  > none of the above are applicable. THANK YOU
                  > Checked by AVG anti-virus system (http://www.grisoft.com).
                  > Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
                  >
                  >[/color]


                  Comment

                  • Melissa

                    #10
                    Re: Programatically Delete Command Button

                    Seems like the perfect solution!!

                    Thanks, Rich.

                    Melissa

                    "Rich P" <rpng123@aol.co m> wrote in message
                    news:40b27696$0 $208$75868355@n ews.frii.net...[color=blue]
                    > Well, there is one thing you could do. On the main form, bring up a
                    > second form which contains the procedure that you want to run just once
                    > on the form open event. Bring up that form and run your procedure.
                    > Once the procedure is run, note that in a table somewhere. From you
                    > main form, check this table to see if the procedure has been run. If
                    > yes, then loop throught the Containers.Docu ments collection to see if
                    > this secondary form exists. If yes, do a DoCmd.DeleteObj ect AcForm,
                    > "YourForm". For Acc2000 you can use the CurrentProject. AllForms
                    > property instead of Containers and Documents. This is kind of
                    > redundant, but it is a technique. So instead of eliminating the button,
                    > you are eliminating the whole form and procedure.
                    >
                    > Rich
                    >
                    > *** Sent via Developersdex http://www.developersdex.com ***
                    > Don't just participate in USENET...get rewarded for it![/color]


                    Comment

                    Working...