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

Clearing a field on BeforeUpdate

Status
Not open for further replies.

rfoye

Programmer
Oct 15, 2004
40
US
Ok, I've searched and can't find an answer to my problem. I am doing a validation by using the BeforeUpdate event. If the value meets certain conditions, I want to Cancel the update and clear the field.

Code:
Sub FieldName_BeforeUpdate(Cancel As Integer)
   ***some code***
   If vVal = vbCancel Then
      Me.ActiveControl.Undo
      Cancel = True
   End If
End Sub

The Cancel=True part is working fine, but the .Undo is not clearing the contents of the field. It selects the contents, but does not delete it.

My question is: How can I totally clear this field?

-------------------
Rob Foye
Database Management
Regions Bank
 
By the way, form is unbound for new records and bound for looking at existing records. It looks like on existing records, it reverts to the previous saved version, but the Unbound New records are not reverting to Null.

-------------------
Rob Foye
Database Management
Regions Bank
 
There is your problem, loop through the unbound controls and set them to Null, they do not have an Undo method.
 
I figured out a workaround. For the bound instance, I can leave the code in the BeforeUpdate event. For the Unbound instance, I set focus on another field, set the value of the first field to null, then return the focus to that field.

-------------------
Rob Foye
Database Management
Regions Bank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top