Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Selstart and SelLength 1

Status
Not open for further replies.

justme1310

Technical User
Jul 23, 2003
16
TT
Hi everyone,

When I enter a numeric value for BP_Sys, the following code is supposed to validate the value. If it falls outside of the accepted range, it is supposed to display an error msg an return and highlight the error value.

What actually happens is the error msg gets displayed, BUT the field after the invalid field (BP_Sys) gets selected and highlighted.

What am I doing wrong?

Code:
Private Sub BP_Sys_AfterUpdate()
If ((BP_Sys < 100) Or (BP_Sys > 130) Or (IsNull(BP_Sys)) Or (Len(BP_Sys) < 3)) Then
  MsgBox ("Invalid entry. Valid range [100 - 130]. Please enter a valid Systolic Blood Pressure.")
  DoCmd.GoToControl ("BP_Sys")
  Me!BP_Sys.SelStart = 0
  Me!BP_Sys.SelLength = Len(Me!BP_Sys) + 1
End If
End Sub

Thanks

Will
 
A more common way to enforce validation rules is to use the BeforeUpdate event procedure and its Cancel argument.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

Thanks for replying to my question.
Do you have an example of how I can achieve my validation using the Before_Update event??


Thanks

Will
 
Private Sub BP_Sys_BeforeUpdate(Cancel As Integer)
If Me!BP_Sys < 100 Or Me!BP_Sys > 130 Or Len(Trim(BP_Sys & "")) < 3 Then
MsgBox ("Invalid entry. Valid range [100 - 130]. Please enter a valid Systolic Blood Pressure.")
Cancel = True
Me!BP_Sys.SelStart = 0
Me!BP_Sys.SelLength = Len(Me!BP_Sys) + 1
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,
Thanks so much for your assistance. The code works just great.

Appreciated.

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top