Run Time Errors when Entering Invalid Data in Combo Box

  • Thread starter Thread starter bg_ie
  • Start date Start date
B

bg_ie

Hi,

I have a combo box on my form which is bound to the form's concerned
table. I have two events functions for this combo as follows -

Private Sub Field1_Change()
If Me.Dirty Then Me.Dirty = False
UpdateLabel
End Sub

Private Sub Field1_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
MsgBox NewData & " is not a valid."
End Sub

I also have a label under the combo which displays some general
statistics (calculated via a query) and I must call Me.Dirty = False
if I wish this label to update correctly.

When I enter an invalid entry into my combo's text box I get the
following error -

Run Time Error 3021: No current record

after the message box is shown.

If I comment out the line with the message box I get the following
error instead -

Run Time Error 2101: The setting you entered isn't valid for this
property.

I'm thinking that because I call Me.Dirty when there is invalid data,
that this is throwing these errors. Would a solution be to set a
global valiable to true when I enter Field1_NotInList and then use the
following -

Private Sub Field1_Change()

If Field1ValidData = True Then
If Me.Dirty Then Me.Dirty = False
UpdateLabel
Else
Field1ValidDate = False
End If
End Sub

Thank you,

Aine.
 
Hi,

I have a combo box on my form which is bound to the form's concerned
table. I have two events functions for this combo as follows -

Private Sub Field1_Change()
If Me.Dirty Then Me.Dirty = False
UpdateLabel
End Sub

Private Sub Field1_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
MsgBox NewData & " is not a valid."
End Sub

I also have a label under the combo which displays some general
statistics (calculated via a query) and I must call Me.Dirty = False
if I wish this label to update correctly.

When I enter an invalid entry into my combo's text box I get the
following error -

Run Time Error 3021: No current record

after the message box is shown.

If I comment out the line with the message box I get the following
error instead -

Run Time Error 2101: The setting you entered isn't valid for this
property.

I'm thinking that because I call Me.Dirty when there is invalid data,
that this is throwing these errors. Would a solution be to set a
global valiable to true when I enter Field1_NotInList and then use the
following -

Private Sub Field1_Change()

If Field1ValidData = True Then
If Me.Dirty Then Me.Dirty = False
UpdateLabel
Else
Field1ValidDate = False
End If
End Sub

Thank you,

Aine.

You might try using Field1_AfterUpdate instead of Field1_Change. I suspect
that the Change event is firing regardless, while the AfterUpdate event
should only fire if the data is valid.

Carl Rapson
 
Back
Top