Set Text Box Control To Blank

D

DrONDeN

I have a procedure that executes on the beforeupdate event of a
textbox (text24). The procedure works out the checkdigit for the
number entered and if there is a discrepancy, a message box appears
telling the user the number is wrong. What I'd like to do is modify
the code as such so that when a discrepancy is found and the user
clicks ok on the message box, focus is returned to (text24) and set to
blank so that the faulty number is gone. Here is the code I am
using.... It's quite crude as I'm only at beginner level, but hey, it
works!

Private Sub Text24_BeforeUpdate(Cancel As Integer)
On Error GoTo StringErr

Dim IntPos1 As Integer
Dim IntPos2 As Integer
Dim IntPos3 As Integer
Dim IntPos4 As Integer
Dim IntPos5 As Integer
Dim IntPos6 As Integer
Dim IntPos7 As Integer
Dim IntPos8 As Integer
Dim IntPos9 As Integer
Dim IntPos10 As String
Dim HematosSum As Integer
Dim IntPos10Check As String
Dim Convert As String

IntPos1 = Mid(Me.Text24, 1, 1)
IntPos2 = Mid(Me.Text24, 2, 1)
IntPos3 = Mid(Me.Text24, 3, 1)
IntPos4 = Mid(Me.Text24, 4, 1)
IntPos5 = Mid(Me.Text24, 5, 1)
IntPos6 = Mid(Me.Text24, 6, 1)
IntPos7 = Mid(Me.Text24, 7, 1)
IntPos8 = Mid(Me.Text24, 8, 1)
IntPos9 = Mid(Me.Text24, 9, 1)
IntPos10 = Mid(Me.Text24, 10, 1)
HematosSum = ((IntPos1 * 6) + (IntPos2 * 3) + (IntPos3 * 7) + (IntPos4
* 9) + (IntPos5 * 10) + (IntPos6 * 5) + (IntPos7 * 8) + (IntPos8 * 4)
+ (IntPos9 * 2) - 1) Mod 11
IntPos10Check = 11 - HematosSum

If IntPos10Check = "10" Then
Convert = "-"
ElseIf IntPos10Check = "11" Then
Convert = "0"
ElseIf IntPos10Check = "9" Then
Convert = "9"
ElseIf IntPos10Check = "8" Then
Convert = "8"
ElseIf IntPos10Check = "7" Then
Convert = "7"
ElseIf IntPos10Check = "6" Then
Convert = "6"
ElseIf IntPos10Check = "5" Then
Convert = "5"
ElseIf IntPos10Check = "4" Then
Convert = "4"
ElseIf IntPos10Check = "3" Then
Convert = "3"
ElseIf IntPos10Check = "2" Then
Convert = "2"
ElseIf IntPos10Check = "1" Then
Convert = "1"
End If

If Convert <> IntPos10 Then
MsgBox "Hematos number incorrect. Please check and try again"
Cancel = True
DoCmd.RunMacro "HematoSetBlank"
ElseIf Len(Me.Text24) < 10 Then
MsgBox "Hematos number incorrect. Please check and try again"
Cancel = True
End If

StringErr:
If Err.Number = 13 Then
MsgBox "Hematos number incorrect. Please check and try again"
Cancel = True
End If


End Sub




Many thanks, Kenny.
 
D

Douglas J. Steele

To set focus on the text box, use

Me.Text24.SetFocus

To blank it out, use

Me.Text24 = Null
 

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