AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Saturday, February 04, 2006

Bound form’s unbound controls do not get updated

Bound form’s unbound controls do not get updated, when underlying recordsource has no records. I just noticed this in Access XP, and found a workaround. Say you have a continuous form, with 2 textboxes on form’s header to filter by date range. I also added few buttons to set these dates to predefined ranges – say this week, last month, etc. So once you have no records in underlying query, and press one of these buttons – values in the textboxes get changed (debug.print shows this), but form still shows old dates! The trick – is to run Me.Recalc at the end of button click event.

4 Comments:

Anonymous Anonymous said...

Bound forms do not get updated when underlying recordsource has no records.
Try this: bind form to read-only empty recordset (or bind read-only form to empty recordset).
Add code to Open and Load events.
Now try to open the form in form view.
Details Section does not paint. Open event fires: Load event does not.
Now close form: Load event fires
(david)

1:03 AM  
Blogger Alex Dybenko said...

Thank you for comment, David.
Anyway - this is quite unexpected behavior, let us hope that this will be fixed in Access 2007

2:52 PM  
Blogger M.Ivashkov said...

I mentioned the same problem in Access 2003 XP. In my case I have a text box that computes week number based on the date in another text box (the source data is an expression). Unfortunately recalc does not help. (refresh, repaint either). It seems to be big bug.
Maxim
site

2:15 PM  
Blogger Unknown said...

Thanks. I had this issue in 2003 and 2000 adps. Re-calculating the form did not work, but recalculating the controls did:
Function DisplayUnboundWhenEmptyRecordset(FormToSetDefaults As Form)
Dim ctl As Control
'Solves a known bug in Access 2000, 2003
'http://accessblog.net/2006/02/bound-forms-unbound-controls-do-not.html
For Each ctl In FormToSetDefaults.FormHeader.Controls
If ctl.ControlType = acTextBox _
Or ctl.ControlType = acCheckBox _
Or ctl.ControlType = acComboBox _
Or ctl.ControlType = acListBox _
Or ctl.ControlType = acOptionGroup Then

ctl.Requery

End If
Next ctl
End Function

9:32 PM  

Post a Comment

<< Home