By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,121 Members | 1,723 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,121 IT Pros & Developers. It's quick & easy.

Programatically Delete Command Button

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Melissa" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
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?


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
Nov 13 '05 #2

P: n/a
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" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
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?

Nov 13 '05 #3

P: n/a
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" <ri*********@hotmail.com> wrote in message
news:2h************@uni-berlin.de...
"Melissa" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
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?


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

Nov 13 '05 #4

P: n/a
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" <co***************************@hotmail.com> wrote in message
news:WA*****************@newssvr16.news.prodigy.co m...
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" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
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?


Nov 13 '05 #5

P: n/a
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" <mk****@earthlink.net>
wrote:
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" <co***************************@hotmail.com> wrote in message
news:WA*****************@newssvr16.news.prodigy.c om...
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" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
> 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?




Nov 13 '05 #6

P: n/a
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.Documents collection to see if
this secondary form exists. If yes, do a DoCmd.DeleteObject 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!
Nov 13 '05 #7

P: n/a
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.DeleteControl(FormName, 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 DeleteCommandButton()
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(frm.Name, acCommandButton)
' Restore form.
DoCmd.Restore
' Set caption.
ctlNew.Caption = "New Command Button"
' Size control.
ctlNew.SizeToFit
' Prompt user to delete control.
strMsg = "About to delete " & ctlNew.Name &". Continue?"
' Define buttons to be displayed in dialog box.
intDialog = vbYesNo + vbCritical + vbDefaultButton2
intResponse = MsgBox(strMsg, intDialog)
If intResponse = vbYes Then
' Delete control.
DeleteControl frm.Name, ctlNew.Name
End If
End Sub
"Melissa" <mk****@earthlink.net> wrote in message
news:%7*******************@newsread2.news.atl.eart hlink.net...
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" <ri*********@hotmail.com> wrote in message
news:2h************@uni-berlin.de...
"Melissa" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
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?


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


---
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
Nov 13 '05 #8

P: n/a
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.
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:dR*******************@news.xtra.co.nz...
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.DeleteControl(FormName, 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 DeleteCommandButton()
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(frm.Name, acCommandButton)
' Restore form.
DoCmd.Restore
' Set caption.
ctlNew.Caption = "New Command Button"
' Size control.
ctlNew.SizeToFit
' Prompt user to delete control.
strMsg = "About to delete " & ctlNew.Name &". Continue?"
' Define buttons to be displayed in dialog box.
intDialog = vbYesNo + vbCritical + vbDefaultButton2
intResponse = MsgBox(strMsg, intDialog)
If intResponse = vbYes Then
' Delete control.
DeleteControl frm.Name, ctlNew.Name
End If
End Sub
"Melissa" <mk****@earthlink.net> wrote in message
news:%7*******************@newsread2.news.atl.eart hlink.net...
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" <ri*********@hotmail.com> wrote in message
news:2h************@uni-berlin.de...
"Melissa" <mk****@earthlink.net> wrote in message
news:1G****************@newsread3.news.atl.earthli nk.net...
> 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?

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


---
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

Nov 13 '05 #9

P: n/a
Seems like the perfect solution!!

Thanks, Rich.

Melissa

"Rich P" <rp*****@aol.com> wrote in message
news:40*********************@news.frii.net...
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.Documents collection to see if
this secondary form exists. If yes, do a DoCmd.DeleteObject 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!

Nov 13 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.