PDA

View Full Version : Solved: Check if Query is Visible



Imdabaum
10-06-2010, 09:44 AM
http://www.vbaexpress.com/forum/showthread.php?t=34376

I'm trying to do some customized Ribbon. But unlike forms and reports, you cannot add a Ribbon name to the properties of a query.

Is there a way to check if a query result has the focus?

Basically I have a ribbon tab hidden and if I open a query I want to make the external data tab visible

hansup
10-07-2010, 01:34 PM
Try this function to check whether the query datasheet has focus.

Public Function QueryDataSheetHasFocus(ByVal pQueryName As String) As Variant
Dim strMsg As String
Dim blnReturn As Variant

On Error GoTo ErrorHandler

blnReturn = (Application.Screen.ActiveDatasheet.Name = pQueryName)

ExitHere:
QueryDataSheetHasFocus = blnReturn
On Error GoTo 0
Exit Function

ErrorHandler:
Select Case Err.Number
Case 2484 ' There is no active datasheet.
'no active datasheet => pQueryName does not have focus
blnReturn = False
Case Else
strMsg = "Error " & Err.Number & " (" & Err.Description _
& ") in function QueryDataSheetActive"
MsgBox strMsg
blnReturn = Null
End Select
GoTo ExitHere
End Function

Imdabaum
10-07-2010, 01:40 PM
Thanks Hansup. Currently I'm using this to show the tab. We'll see if this function allows me to make the alternate callback to hide it again.

Imdabaum
10-07-2010, 02:02 PM
Sorry forgot to actually post the code.

Public Sub HandleQueryOnAction(control As IRibbonControl)
DoCmd.OpenQuery control.Tag, acNormal
Call RefreshRibbon(Tag:="TabExternalData")
' Dim rtab As IRibbonUI
End Sub
Sub GetVisible(ByRef control As IRibbonControl, ByRef visible)
If control.Tag = MyTag Then
visible = False
Else
visible = True
End If
End Sub
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set Rib = ribbon
End Sub
Sub RefreshRibbon(Tag As String)
MyTag = Tag
If Rib Is Nothing Then
MsgBox "Error, restart the database. Ribbon wasn't loaded successfully."
Else
Rib.Invalidate
End If
End Sub

Imdabaum
10-08-2010, 10:36 AM
Okay I found a solution to reach my overall goal. Not sure why I didn't think of it earlier, but yeah. Too little sleep maybe...

I'm just going to build a form with the recordset bound to the query and use the form's Ribbon property.

hansup
10-08-2010, 10:57 AM
Good. I was lost with the ribbon stuff. I hoped the function to check whether the query datasheet has focus could be useful despite my ribbon ignorance. :friends: