Access 2003 - Is this a bug?

  • Thread starter J_Goddard via AccessMonster.com
  • Start date
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
 
K

Klatuu

Me.Undo and Cancel = True (more descriptive than -1) are not at all the same.
Setting Cancel to True has no effect on the current record. It only cancels
the update. Me.Undo discards any changes made to the record.

As to the bug issue, it is possible you have SP3 installed? It has caused
some unusual problems. One known problem is with formatted controls.
--
Dave Hargis, Microsoft Access MVP


J_Goddard via AccessMonster.com said:
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
 
J

J_Goddard via AccessMonster.com

Hi -

Fortunately the subform can only update the checkbox (though other fields are
displayed), so the difference between Cancel and Undo doesn't matter in this
case. But if the subform did update other data, there would be a problem
indeed. Why I think it might be a bug is the difference between 2000 and
2003.

I only have SP2 installed (thank goodness, from what I have seen), so it's
not that.

John

Me.Undo and Cancel = True (more descriptive than -1) are not at all the same.
Setting Cancel to True has no effect on the current record. It only cancels
the update. Me.Undo discards any changes made to the record.

As to the bug issue, it is possible you have SP3 installed? It has caused
some unusual problems. One known problem is with formatted controls.
[quoted text clipped - 54 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top