How to blank a txtbox

w0nger

New member
Local time
Today, 04:15
Joined
Sep 11, 2008
Messages
8
I've got a txt that REQUIRES something to be in it, but everytime someone edits a record i want the txtbox to blank out so they have to re-input the data. i tried putting in:

Me.txtbox = ""

but I get an error that says

Field.txtbox. cannot be zero length string.

However, if I enable zero length string, then the record can be saved without anything being put into the txtbox.

Solution?
 
Your best bet is to continue with the Me.textbox = "" and use the Before Update event to test for valid data entered. You will notice, if an error is found, you set Cancel=True and probably want to do a msgbox message.
 
If i were to add an if statement to make sure there was something in the txtbox, in the beforeupdate, what would it be?
 
If you just want to ensure something was entered...
Code:
Private Sub textbox_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.textbox)= True then
        Msgbox "textbox cannot be empty"
        Cancel = True
    End if
End Sub
 
this isnt so easy, as just managing that text box.

assume you have a new, or a previous, but now unedited record. When you change anything, at thisp oint the record becomes dirty, so at this point you want the text field to clear.

this will need a lot of code, as there is no single event to handle this, (on dirty) i think

so instead, deal with this text in a beforeupdate event. When you save the record you will get a before update event. you wont get a before update event if you dont change the record.

at this point, explicitly get the new text by opening an inputbox

newtext=inputbox("Enter new text: ")

and assign the newtext to the saved field

saveddata = newtext in the before update event. You can show the previoussaveddata in a locked textbox, so the users dont edit it directly.

You can validate their entry as well, so if it isnt appropriate, you can refuse the save record, until valid data HAs been input

It depends exactly what you sort of data your users are entering in this box. If its just for record purposes, for instance, at this point you could save the date and time, the windows login, and terminal ID being used to handle the edit.
 
that write up really helped. I ended up doing a beforeupdate event and creating a msg box that updated the field. thx. I was just thinking in the right direction. Appreciate it.
 
wOnger said:
However, if I enable zero length string, then the record can be saved without anything being put into the txtbox.
Just to clarify, a record can be saved without anything being put into it whether or not Zero-length String is allowed! A textbox that hasn't had anything entered into it is neither a Zero-length String nor a non-Zero-length String, it's Null. Null and Zero-length String are not the same thing.
 

Users who are viewing this thread

Back
Top Bottom