validating data

  • Thread starter Thread starter Heidi
  • Start date Start date
H

Heidi

I have a subform in which users can edit previously
entered data for dealers. When the user tries to pull the
edit screen up, a query that makes up the subform asks
what month and what year the user wants to edit (I just
made a parameter query for this subform). Also, this edit
screen has some validations in it. For example, if
ReportType = P, then Weight cannot be null. The problem
is when the user pulls up a dealer with no data to edit
and then tries to exit out of this edit screen, I get a
runtime error #2427 -- that I have entered and expression
that has no value. How do I resolve this problem?
 
-----Original Message-----
I have a subform in which users can edit previously
entered data for dealers. When the user tries to pull the
edit screen up, a query that makes up the subform asks
what month and what year the user wants to edit (I just
made a parameter query for this subform). Also, this edit
screen has some validations in it. For example, if
ReportType = P, then Weight cannot be null. The problem
is when the user pulls up a dealer with no data to edit
and then tries to exit out of this edit screen, I get a
runtime error #2427 -- that I have entered and expression
that has no value. How do I resolve this problem?

Heidi, you can add an On Error Goto (sdfasdf) clause in
the _BeforeUpdate handler for the subform. THe "sdfasdf"
line of code will call a subroutine to error-trap, inwhich
you could have something like

Select Case Err.Number
 
-----Original Message-----
I have a subform in which users can edit previously
entered data for dealers. When the user tries to pull the
edit screen up, a query that makes up the subform asks
what month and what year the user wants to edit (I just
made a parameter query for this subform). Also, this edit
screen has some validations in it. For example, if
ReportType = P, then Weight cannot be null. The problem
is when the user pulls up a dealer with no data to edit
and then tries to exit out of this edit screen, I get a
runtime error #2427 -- that I have entered and expression
that has no value. How do I resolve this problem?

sorry for the previous cutoff, must've hit the send button.

Anyway, in the _BeforeUpdate handler on your subform you
need to have an On Error Goto line that directs program
control to a subroutine call. The called subroutine traps
the VBA error like this:

Select Case Err.Number
Case 2427
DoCmd.SetWarnings False
(do more stuff)
Case nnnn
(do stuff)
...
Case Else
End Select

Just remember to include a DoCmd.SetWarnings True in teh
line immediately after the one where you called the error-
trap subroutine.

HTH,
 
Back
Top