Y
Yarik
Hi,
This feels really weird... like a bug in Access or something.
I have a bound continuous form and a bunch of unbound controls in the
header section to let the user quickly filter the records shown on the
form.
This is the code simplified by stripping of all the details that I
believe are not important (no validation of user input, no error
handling, etc.):
' User is supposed to press the Refresh command button
' after specifying the desired filtering criterion
'
--------------------------------------------------------------------------------
Private Sub cmdRefresh_Click()
' Based on filtering criterion specified by unbound controls
' we construct an SQL query and ask the form to show its
results.
' For example, something along these lines:
...
' Get ID of a customer currently selected in unbound combobox:
sqlCriteria = sqlCriteria & "CustomerID = " &
Me.comboCustomers
' Get date specified in unbound text control:
sqlCriteria = sqlCriteria & "ReceivedOn > " & Me.textMinDate
....
Me.RecordSource = "select * from Orders where " & sqlCriteria
End Sub
' This is a button that user can press to quickly specify that
' only today's orders are to be shown.
' (NB: User still has to press Refresh button afterwards
' for the new filter to be applied.)
Private Sub cmdSetMinDateToNow()
Me.textMinDate = Now()
End Sub
That's it. It works like a charm most of the time. However, the
problem occurs whenever the SQL query does not return any records. The
simple code of the cmdSetMinDateToNow_Click event handler stops
working properly: the unbound text control textMinDate keeps showing
its old value after its value is changed by
Me.textMinDate = Now()
line. It really looks like some problem with refreshing of the text
control: in debugger, I can see that the value has been actually
changed, but the control does not show the change to the user.
Interestingly enough, the control does get refreshed if user does some
woodoo like
-- hovering a mouse over the stubborn unbound control (sometimes does
not help)...
-- clicking the stubborn control first (to set focus to it) and *then*
pressing the cmdSetMinDateToToday button again...
-- trying to enter some value into another unbound control...
-- etc.
Is this a known bug in MS Access?
The only workaround that we've found so far is using the unbound
control's Requery() method to "kick" it right after changing its
value. For example:
Private Sub cmdSetMinDateToNow()
Me.textMinDate = Now()
Call Me.textMinDate.Requery() ' Kick it...
End Sub
It works, but it's ugly. By any chance, does anybody know any
alternative solution?
FWIW: This happens with Access 2003, in ADP project (not MDB). The
backend is SQL Server 2000.
Thank you!
This feels really weird... like a bug in Access or something.
I have a bound continuous form and a bunch of unbound controls in the
header section to let the user quickly filter the records shown on the
form.
This is the code simplified by stripping of all the details that I
believe are not important (no validation of user input, no error
handling, etc.):
' User is supposed to press the Refresh command button
' after specifying the desired filtering criterion
'
--------------------------------------------------------------------------------
Private Sub cmdRefresh_Click()
' Based on filtering criterion specified by unbound controls
' we construct an SQL query and ask the form to show its
results.
' For example, something along these lines:
...
' Get ID of a customer currently selected in unbound combobox:
sqlCriteria = sqlCriteria & "CustomerID = " &
Me.comboCustomers
' Get date specified in unbound text control:
sqlCriteria = sqlCriteria & "ReceivedOn > " & Me.textMinDate
....
Me.RecordSource = "select * from Orders where " & sqlCriteria
End Sub
' This is a button that user can press to quickly specify that
' only today's orders are to be shown.
' (NB: User still has to press Refresh button afterwards
' for the new filter to be applied.)
Private Sub cmdSetMinDateToNow()
Me.textMinDate = Now()
End Sub
That's it. It works like a charm most of the time. However, the
problem occurs whenever the SQL query does not return any records. The
simple code of the cmdSetMinDateToNow_Click event handler stops
working properly: the unbound text control textMinDate keeps showing
its old value after its value is changed by
Me.textMinDate = Now()
line. It really looks like some problem with refreshing of the text
control: in debugger, I can see that the value has been actually
changed, but the control does not show the change to the user.
Interestingly enough, the control does get refreshed if user does some
woodoo like
-- hovering a mouse over the stubborn unbound control (sometimes does
not help)...
-- clicking the stubborn control first (to set focus to it) and *then*
pressing the cmdSetMinDateToToday button again...
-- trying to enter some value into another unbound control...
-- etc.
Is this a known bug in MS Access?
The only workaround that we've found so far is using the unbound
control's Requery() method to "kick" it right after changing its
value. For example:
Private Sub cmdSetMinDateToNow()
Me.textMinDate = Now()
Call Me.textMinDate.Requery() ' Kick it...
End Sub
It works, but it's ugly. By any chance, does anybody know any
alternative solution?
FWIW: This happens with Access 2003, in ADP project (not MDB). The
backend is SQL Server 2000.
Thank you!