Public Sub WhatsThis()
Dim cbr As CommandBar
Dim btn As CommandBarButton
On Error GoTo ProcError
For Each cbr In Application.CommandBars
Set btn = cbr.Controls.Add(1, , , , True)
btn.Caption = "What's This"
btn.OnAction = "WhatsThisMenu"
btn.BeginGroup = True
NextBar:
Next
ProcExit:
On Error Resume Next
Set btn = Nothing
Set cbr = Nothing
Exit Sub
ProcError:
Resume NextBar
End Sub
Public Sub WhatsThisMenu()
Debug.Print "Name: ";CommandBars.ActionControl.Parent.Name
Debug.print "Index: ";commandbars.ActionControl.Parent.Index
msgbox "Name : " & Commandbars.ActionControl.Parent.Name & vbcrlf _
& "Index: " & Commandbars.ActionControl.Parent.Index
End Sub
commandbars(127).Enabled = False
commandbars("Form View Popup").Enabled = False
Public Sub HideBar(BarName As String, Optional IsHidden As Boolean = True)
Dim ctrl As Object 'CommandBarControl '
On Error GoTo ProcError
For Each ctrl In CommandBars(BarName).Controls
If ctrl.BuiltIn = true then ctrl.Visible = Not IsHidden
Next
ProcExit:
Exit Sub
ProcError:
Select Case Err.Number
Case 5, -2147024809
MsgBox "Invalid commandbar name"
Case Else
Debug.Print Err.Number, Err.Description
End Select
End Sub
Dim ctrl As Object 'CommandBarControl
With CommandBars("Form Datasheet Row")
Set ctrl = .Controls.Add(1, , , , True)
ctrl.Caption = "Display &Details"
ctrl.OnAction = "SomeFormDisplayRecordDetails"
ctrl.Visible = False
ctrl.Enabled = true
End With
HideBar "Form Datasheet Row"
Commandbars("Form Datasheet Row").Controls("Display &Details").Visible = -1
Public Sub SomeFormDisplayRecordDetails
Dim strCriteria as string
strCriteria = "[ID] = " & Forms!MainForm.subFormControl.Form.txt_ID
Docmd.Openform "SomeFormDisplayDetails", , , strCriteria
End Sub
HideBar "Form Datasheet Row", False
Commandbars("Form Datasheet Row").Controls("Display &Details").Visible = False
Option Compare Database
Option Explicit
Dim strAction As String
Dim intDataShtColCnt As Integer
Private Sub Form_Open(Cancel as Integer)
'Determine the number of columns in the datasheet
intDataShtColCnt = DatasheetColumnCount(Me)
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = acRightButton Then DatasheetPopups me, intDataShtColCnt
End Sub
Private Sub txt_SomeControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'It is necessary to put this code in the MouseUp event of each control in the datasheet
'which you want to be able to use the "form datasheet cell" shortcut menu
If Button = acRightButton Then CommandBars("form datasheet cell").ShowPopup
End Sub
Public Function DatasheetColumnCount(frm As Form) As Variant
Dim ctrl As Control
Dim intCtrlCount As Integer
DatasheetColumnCount = Null
If frm.CurrentView <> 2 Then Exit Function
For Each ctrl In frm.Section(acDetail).Controls
If ctrl.ControlType <> 100 Then
intCtrlCount = intCtrlCount + 1
End If
Next
DatasheetColumnCount = intCtrlCount
End Function
Public Sub DatasheetPopups(frm As Form, ColCount As Integer)
If (frm.SelHeight = frm.Count) And (frm.SelWidth = 1) Then
CommandBars("form datasheet column").ShowPopup
ElseIf frm.SelWidth = ColCount Then
CommandBars("form datasheet row").ShowPopup
End If
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Author
Commented:I didn't realize there was a way to center the text, or I certainly would have used it.
Author
Commented:Commented: