473,503 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 13 '05 #1
9 5708
"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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5912
by: Toralf Kirsten | last post by:
Hi, we installed db2 v8.1 on red hat linux 9. Unfortunately, the backspace and the delete button doesn't work in the right way. Instead of deleting chars, control characters are inputed. That...
3
3955
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
1
3489
by: Susan | last post by:
I have a bound form and subform and am trying to enter the data in both forms programatically. The Linkmaster and Linkchild properties are set. My intent is to be able to look at the data before it...
3
2003
by: Stewart Graefner | last post by:
What do I need to use to be able to make information in a table be deleteable by a User? The table I have tracks Vacation time. It has two fields Vacation Dates and Days taken(Default value 0). The...
3
2773
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
3
13725
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
17234
by: The Woo | last post by:
Can one programatically create a file folder which has the same name as a key field, using a command button? Or, Can there be a a command button which opens up a directory tree to a specified...
3
3794
by: Kevin M | last post by:
I have one table and have created a form from that table. Also, I have created a delete query. I want to but a button on the form which will delete all records from the table; however, I cannot get...
0
8103
by: kkkanoor | last post by:
I am trying to schedule tasks in Windows from my C# program. The tasks get listed in Windows Schedule Tasks list, but it is not getting invoked. It seems I need to give the user name and password to...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.