Runtime error 3315

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have a combo box on my form. Its default value is not set. The combo is to
select text values to be inserted into a text field "AccountID" of table
"Payments".
When the combo is updated the following code runs:

Private Sub MyCombo_AfterUpdate()
Me.MyCombo.DefaultValue = Me.MyCombo
End Sub

The above code works fine. But....

On the form there is also a check box. When it is checked the following code
runs:

Private Sub MyCheckBox_AfterUpdate()
If Me.MyCheckBox = True Then
Me.MyCombo.Value = Me.MyCombo.DefaultValue
End If
End Sub

The code works fine starting from the second enetered record.
On the first record (when the default value of the combo is supposed to be
Null) I get runtime error 3315 "Field 'tblPayments.AccountID' cannot be a
zero-length string."

Thank you in advance for any help!
 
Mike,
you need to stop the code trying use a default value when the default value
is missing.

The code below checks to see if there is a default value for the combo,
and only goes on to set the value if the default value does exist.

Private Sub MyCheckBox_AfterUpdate()
If Me.MyCheckBox = True Then
If Len(Me.MyCombo.DefaultValue & vbNullString) >0 Then
Me.MyCombo.Value = Me.MyCombo.DefaultValue
Else
End If
End If
End Sub

Jeanette Cunningham
 
Thank you, Jeanette!!!





Jeanette Cunningham said:
Mike,
you need to stop the code trying use a default value when the default value
is missing.

The code below checks to see if there is a default value for the combo,
and only goes on to set the value if the default value does exist.

Private Sub MyCheckBox_AfterUpdate()
If Me.MyCheckBox = True Then
If Len(Me.MyCombo.DefaultValue & vbNullString) >0 Then
Me.MyCombo.Value = Me.MyCombo.DefaultValue
Else
End If
End If
End Sub

Jeanette Cunningham
 
Back
Top