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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear textbox

Status
Not open for further replies.

poporacer

Programmer
Oct 2, 2007
53
US
I have a form to input new contacts. The form has a text box for the entry of a Id# for the contact. What I want to do is check this ID# and if it already exists, let the user know and clear out the text box and return to the textbox for rentry of the correct ID#. For some reason I can't get the textbox to clear... Here is the code I am using

Private Sub txtCDCNum_BeforeUpdate(Cancel As Integer)

If Not IsNull(DLookup("[CDCNum]", "tblInmates", "[CDCNum]= '" & StrConv(txtCDCNum, vbUpperCase) & "'")) Then
Me.txtCDCNum.Undo '**<-- This doesn't clear textbox
Cancel = True
MsgBox "This CDC Number already exists. Please enter a new CDC Number.", vbOKOnly, "Duplicate CDC Number"
End If

End Sub



Any suggestions?
 
What about this instead ?
Me!txtCDCNum.Value = Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That doesn't work because you cant change the value in a control in the before update event....the data isn't committed to the control until after the control is updated
 
And this ?
Code:
If Not IsNull(DLookup("CDCNum", "tblInmates", "CDCNum='" & Me!txtCDCNum & "'")) Then
  MsgBox "This CDC Number already exists. Please enter a new CDC Number.", vbOKOnly, "Duplicate CDC Number"
  Cancel = True
  Me!txtCDCNum.Undo
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top