Paul,
How do I force a requery of a combo box in a table in datasheet view ? Is
there another shortcut key ?
If anyone has a simpler way than the below, I'd be obliged, but the below works in most cases for me (and could be refiined a bit
I'm sure)
Good luck
--
Malcolm Cook
Stowers Institute for Medical Research - Kansas City, MO USA
Public Function ACControlRequery(Optional ctl As Access.Control)
'HowTo: force a requery of a combo box in a table in datasheet (or table) view
' add to your AutoKeys macro an entry with:
' Macro Name: "^+{F9}" (which is control-shift-F9)
' Action: "RunCode"
' Function Name: "=ACControlRequery()"
' (note: F9 _should_ do this but does NOT in ACC2002)
If ctl Is Nothing Then Set ctl = Screen.ActiveControl
On Error GoTo HandleErr
With ACControlParentForm(ctl)
If .Dirty Then .Dirty = False ' which saves the record - this may raise an error - i.e. record can't be saved for some reason!
End With
With ctl
Select Case .ControlType
Case 115 'which is a "Table View Text Box" - not documented AFAIK
.Requery
Case acListBox, acComboBox
If (.RowSourceType = "Tables/Views/Functions") Then
.Requery
End If
End Select
' TODO: what if ctl has no RowSource, but rather has a (unbound) recordset? Then, ctl.recordset.requery? probably. untested.
End With
ExitHere:
Exit Function
HandleErr:
Select Case Err.Number
Case Else ' unanticipated!
MsgBox Err.description
End Select
Resume ExitHere
' End Error handling block.
End Function
Public Function ACControlParentForm(ctl As Access.Control) As Access.Form
'returns the form the control is 'on', searching up through parents if needed
'(which may be intervening tab controls / pages). Works also if ctl is on
'native access table
Dim Parent As Object
Dim ParentTypeName As String
Set Parent = ctl
Do
Set Parent = Parent.Parent
ParentTypeName = TypeName(Parent)
Loop Until ParentTypeName Like "Form_*" Or ParentTypeName = "Subform" Or (ParentTypeName Like "T_*") 'NB: T_ is used by acces for
naming table objects displayed without a form"
Set ACControlParentForm = Parent.Form
End Function