Chi Is Current
asked on
Runtime Error: 2108
The SetFocus command in this IF statement results in a Runtime error #2108 - must save the field. The statement is in the BeforeUpdate event of the 'ProductDesc' field.
I'd appreciate knowing how to make this work.
If IsNull(Forms![frmNewProduc t]![cmbVen dor].Value ) Then
MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
Cancel = True
Me![ProductDesc].Undo
>>> Forms![frmNewProduct]![cmb Vendor].Se tFocus
Exit Sub
End If
Thank you, Jacob
I'd appreciate knowing how to make this work.
If IsNull(Forms![frmNewProduc
MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
Cancel = True
Me![ProductDesc].Undo
>>> Forms![frmNewProduct]![cmb
Exit Sub
End If
Thank you, Jacob
better if you can upload the db..
ASKER
Private Sub ProductDesc_BeforeUpdate(Cancel As Integer)
'On Error GoTo Err_ProductDesc_BeforeUpdate
If IsNull(Forms![frmNewProduct]![cmbVendor].Value) Then
MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
Cancel = True
Me![ProductDesc].Undo
Forms![frmNewProduct]![cmbVendor].SetFocus
Exit Sub
End If
End Sub
Try this:
Me![ProductDesc].Undo
Me.Dirty = False
Forms![frmNewProduct]![cmb Vendor].Se tFocus
Me![ProductDesc].Undo
Me.Dirty = False
Forms![frmNewProduct]![cmb
ASKER
Adding: Me.Dirty = False -> Run-time error #3058 Index or primary key cannot contain a null value.
Hmmmmm this is happening in a new record......
Hmmmmm this is happening in a new record......
you are attempting to do a validation..why do you need to force saved the record when validation fails?
You also need to set focus to the form before setting focus to the control:
If [frmNewProduct] is a subform, you can use:
Me![ProductDesc].Undo
Me.Dirty = False
Me![frmNewProduct].SetFocu s
Me![frmNewProduct]![cmbVen dor].SetFo cus
If [frmNewProduct] is a subform, you can use:
Me![ProductDesc].Undo
Me.Dirty = False
Me![frmNewProduct].SetFocu
Me![frmNewProduct]![cmbVen
You also need to set focus to the form before setting focus to the control:
Me![ProductDesc].Undo
Me.Dirty = False
Forms![frmNewProduct].SetF ocus
Forms![frmNewProduct]![cmb Vendor].Se tFocus
If [frmNewProduct] is a subform, you can use:
Me![ProductDesc].Undo
Me.Dirty = False
Me![frmNewProduct].SetFocu s
Me![frmNewProduct]![cmbVen dor].SetFo cus
Me![ProductDesc].Undo
Me.Dirty = False
Forms![frmNewProduct].SetF
Forms![frmNewProduct]![cmb
If [frmNewProduct] is a subform, you can use:
Me![ProductDesc].Undo
Me.Dirty = False
Me![frmNewProduct].SetFocu
Me![frmNewProduct]![cmbVen
<Adding: Me.Dirty = False -> Run-time error #3058 Index or primary key cannot contain a null value.>
change
Me.Dirty = False
to
Me.Undo
change
Me.Dirty = False
to
Me.Undo
me.undo will clear all the entry you made, are you sure you want to do this?
ASKER
OK - The statement now reads:
If IsNull(Forms![frmNewProduc t]![cmbVen dor].Value ) Then
MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
Cancel = True
'Me![ProductDesc].Undo
'Me.Dirty = False
Me.Undo
Forms![frmNewProduct].SetF ocus
Forms![frmNewProduct]![cmb Vendor].Se tFocus
Exit Sub
End If
And results in the Run-time error #2108 'Must first save the field...
This is not a subform, all the text boxes referenced are on this form.
Thank you for your assistance here!
If IsNull(Forms![frmNewProduc
MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
Cancel = True
'Me![ProductDesc].Undo
'Me.Dirty = False
Me.Undo
Forms![frmNewProduct].SetF
Forms![frmNewProduct]![cmb
Exit Sub
End If
And results in the Run-time error #2108 'Must first save the field...
This is not a subform, all the text boxes referenced are on this form.
Thank you for your assistance here!
how is the form "frmNewProduct" related to the form you are runnning the codes from?
or what is the purpose of the frmNewProduct in the current operation?
or what is the purpose of the frmNewProduct in the current operation?
like what i said in my first post
<better if you can upload the db..>
<better if you can upload the db..>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
'Bout sez it all. Thank you! Jacob
"'Bout sez it all. Thank you! Jacob"
You are welcome ...
mx
You are welcome ...
mx