Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete the active CommandBar Button

Status
Not open for further replies.

snakehips2000

Programmer
Nov 10, 2003
95
GB
I need a way to allow a user to click on a commandbar button (listing a series of 'favourite' forms) and for Access VBA to delete that button programmatically.

I quickly realised that the problem was probably due me trying to delete the button from the function contained within the "OnAction" macro.

Then, I came across the following code thinking that this might get around it but I still can't get it to work properly.

When I click on the CommandBar button, I get "Method 'Delete' of object '_CommandBarButton' failed". Strangely though, if you create several instances of the same button, the code works OK. It's only when you get down to the last remaining button that the error occurs.

Any thoughts? Thanks, Brian
******************************************

Sub CreateMenu()
With CommandBars("InformmenuHOF").Controls(2).CommandBar.Controls(4)
With .Controls.Add(msoControlButton)
.Caption = "Clicktodelete"
.OnAction = "DeleteMyself"
.Visible = True
End With
End With
End Sub

Sub DeleteMyself()
With CommandBars("InformmenuHOF").Controls(2).CommandBar.Controls(4)
.Controls("Clicktodelete").Tag = "DELME"
End With
DeleteLater
End Sub

Sub DeleteLater()
Dim Cbc As CommandBarButton

Set Cbc = CommandBars.FindControl(, , "DELME")
If Not Cbc Is Nothing Then
Cbc.Delete
End If
End Sub
 
I have not tried any of this, but it seems to me that you would need to move the focus from the button to something else. It might then allow you to do the delete.

Paul
 
That was my first port of call but it doesn't seem to have any effect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top