set text box to blank(Null)

N

NNlogistics

Sorry for this question. It seems to be well covered but I quess I'm thicker
than most. I am trying to set a text box to nothing - Blank - Null. I
thought I understand the difference but here goes.

My code looks like this
If Left(Me.txtProductCode, 1) <> 1 Then
MsgBox ("Service Charge Codes always start with '1'")
Cancel = True
Me.txtProductCode.Value = Null
=""

The underlying field is a text field
Exit Sub
End If
I get a run Time error 2115

Ive tried = ""
tried Me.txtProductCode = null
 
A

Allen Browne

If the field's Required field is set to Yes, then the attempt to set the
field to null will fail.

Instead, undo the field:

Me.txtProductCode.Undo
 
D

Douglas J. Steele

Take a look at the error message associated with that error:

"The macro or function set to the BeforeUpdate or ValidationRule property
for this field is preventing @ from saving the data in the field.@* If this
is a macro, open the macro in the Macro window and remove the action that
forces a save (for example, GoToControl).
* If the macro includes a SetValue action, set the macro to the AfterUpdate
property of the control instead.
* If this is a function, redefine the function in the Module window."

(If your error handling isn't showing the error's Description property, you
can go to the immediate window, type

?AccessError(2115)

and hit Enter)

In other words, it sounds as though you're trying to run that code in the
BeforeUpdate event of the txtProductCode control. You cannot change a
control's value in its BeforeUpdate event. Either leave the value there,
making the user rekey it, or put your check into the Form's BeforeUpdate
event.
 

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