Changing null to "" in a form field.

L

LAS

What is the recommended way to make sure that when the contents of an
unbound field are deleted, the contents will contain an empty string instead
of null?

TIA
LAS
 
K

Ken Snell

You could use the AfterUpdate event of the control:

Private Sub NameOfControl_AfterUpdate()
If Len(Me.NameOfControl.Value & "") = 0 Then Me.NameOfControl.Value = ""
End Sub

or

Private Sub NameOfControl_AfterUpdate()
Me.NameOfControl.Value = Nz(Me.NameOfControl.Value, "")
End Sub
 
L

LAS

Thanks much!

Ken Snell said:
You could use the AfterUpdate event of the control:

Private Sub NameOfControl_AfterUpdate()
If Len(Me.NameOfControl.Value & "") = 0 Then Me.NameOfControl.Value = ""
End Sub

or

Private Sub NameOfControl_AfterUpdate()
Me.NameOfControl.Value = Nz(Me.NameOfControl.Value, "")
End Sub
 
D

David W. Fenton

You could use the AfterUpdate event of the control:

Private Sub NameOfControl_AfterUpdate()
If Len(Me.NameOfControl.Value & "") = 0 Then
Me.NameOfControl.Value = "" End Sub

I don't understand this, since it's going to set the value to a ZLS
when it's already a ZLS. You only need to do it when it's Null:

If IsNull(Me!NameOfControl) Then
Me!NameOfControl = vbNullString
End If
 

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