"Clear" Textbox (delete data)

T

Tom

The function below throws an error message if the entered
data into textbox field/table is NOT unique.

After I acknowledge the error message, I would like
to "empty" the entered textbox field (instead of having
the cursor still "blink" at the end of the data value.

I have tried the following (below the line of code
containing the MsgBox "...."

BilletCode.SetFocus
BilletCode.Text = ""

This, however, does not work. Does anyone know how to
add the code that will clear the textbox?

Thanks,
Tom



********* This is the current function:

Private Sub BilletCode_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.BilletCode) Then
If Me.BilletCode.Value = Me.BilletCode.OldValue
Then
'Do Nothing
Else
strWhere = "BilletCode = """ & Me.BilletCode
& """"
varResult = DLookup
("BilletCode", "tbl_BilletCodes", strWhere)

If Not IsNull(varResult) Then
Cancel = True
MsgBox "Billet code '" & varResult & "'
already exists. Please enter a new billet code or cancel
operation!"

End If

End If
End If
End Sub
 
W

Wayne Morgan

Cancel = True
Me.BilletCode.Undo

It shouldn't be necessary to set the focus to the control, since you canceled the update
the focus should still be at the control.
 
T

Tom

Wayne:

That's perfect!!!!

Tom

-----Original Message-----
Cancel = True
Me.BilletCode.Undo

It shouldn't be necessary to set the focus to the
control, since you canceled the update
 

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