J
J_Goddard via AccessMonster.com
Hi All -
I have encountered curious behaviour in MS Access 2003 which to me seems to
be a bug. I have an application which has a sub-form used in several other
main forms. The subform is used to select which records in a table will be
processed by the main form, and the records are selected by clicking a
checkbox. Depending on which main form is being used, the maximum number of
records which can be selected in the sub-form can vary from 2 upwards. To
"enforce" this limit, I have the following code in the Before Update event of
the checkbox, to cancel the selection if the user selects too many:
Private Sub Select_BeforeUpdate(Cancel As Integer)
If Me![Select] Then
If Me.Parent![selected group count] + 1 > Me.Parent.max_groups Then
FormattedMsgBox "You have already selected " & Me.Parent.max_groups &
" groups - un-select some if you wish to select this one"
Cancel = -1
Exit Sub
Else
Me.Parent![selected group count] = Me.Parent![selected group count] +
1
If [Report Column Number] = 0 Then
Me.Parent.Next_Column = Me.Parent.Next_Column + 1
[Report Column Number] = Me.Parent.Next_Column
Else
[Report Column Number] = [Report Column Number] * -1
End If
End If
Else
Me.Parent![selected group count] = Me.Parent![selected group count] - 1
[Report Column Number] = [Report Column Number] * -1
End If
End Sub
In Access 2000 this works fine - the error message is displayed, the checkbox
is cleared, and the main form textbox Me.Parent![selected group count] is
left unchanged; this is the expected behaviour.
Access 2003, the error message is displayed, and checkbox is cleared
(correctly), but I noticed that the main form form textbox Me.Parent!
[selected group count] WAS being changed ( it decreased by one ) when I
clicked another record in the subform. I discovered that the Before Update
event code was being executed not only when I clicked on the checkbox in the
subform, but AGAIN (for the same record) when I clicked anywhere in another
record in the subform, and it incorrectly updated the textbox on the main
form.
Surely this is a bug in Access 2003 - why would the Before Update event fire
a second time after the first one was cancelled?
Fortunately, the fix was easy - I added Me.Undo before the Cancel = -1 line,
and it worked fine (in both Versions), but having to use Cancel = -1 and Me.
Undo seems to be redundant.
Just thought it useful to point this out.
John
I have encountered curious behaviour in MS Access 2003 which to me seems to
be a bug. I have an application which has a sub-form used in several other
main forms. The subform is used to select which records in a table will be
processed by the main form, and the records are selected by clicking a
checkbox. Depending on which main form is being used, the maximum number of
records which can be selected in the sub-form can vary from 2 upwards. To
"enforce" this limit, I have the following code in the Before Update event of
the checkbox, to cancel the selection if the user selects too many:
Private Sub Select_BeforeUpdate(Cancel As Integer)
If Me![Select] Then
If Me.Parent![selected group count] + 1 > Me.Parent.max_groups Then
FormattedMsgBox "You have already selected " & Me.Parent.max_groups &
" groups - un-select some if you wish to select this one"
Cancel = -1
Exit Sub
Else
Me.Parent![selected group count] = Me.Parent![selected group count] +
1
If [Report Column Number] = 0 Then
Me.Parent.Next_Column = Me.Parent.Next_Column + 1
[Report Column Number] = Me.Parent.Next_Column
Else
[Report Column Number] = [Report Column Number] * -1
End If
End If
Else
Me.Parent![selected group count] = Me.Parent![selected group count] - 1
[Report Column Number] = [Report Column Number] * -1
End If
End Sub
In Access 2000 this works fine - the error message is displayed, the checkbox
is cleared, and the main form textbox Me.Parent![selected group count] is
left unchanged; this is the expected behaviour.
Access 2003, the error message is displayed, and checkbox is cleared
(correctly), but I noticed that the main form form textbox Me.Parent!
[selected group count] WAS being changed ( it decreased by one ) when I
clicked another record in the subform. I discovered that the Before Update
event code was being executed not only when I clicked on the checkbox in the
subform, but AGAIN (for the same record) when I clicked anywhere in another
record in the subform, and it incorrectly updated the textbox on the main
form.
Surely this is a bug in Access 2003 - why would the Before Update event fire
a second time after the first one was cancelled?
Fortunately, the fix was easy - I added Me.Undo before the Cancel = -1 line,
and it worked fine (in both Versions), but having to use Cancel = -1 and Me.
Undo seems to be redundant.
Just thought it useful to point this out.
John