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![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

Thank you, Jacob
LVL 2
Chi Is CurrentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
better if you can upload the db..
0
Chi Is CurrentAuthor Commented:

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

Open in new window

0
thenelsonCommented:
Try this:
        Me![ProductDesc].Undo
        Me.Dirty = False
        Forms![frmNewProduct]![cmbVendor].SetFocus
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Chi Is CurrentAuthor Commented:
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......
0
Rey Obrero (Capricorn1)Commented:
you are attempting to do a validation..why do you need to force saved the record when validation fails?
0
thenelsonCommented:
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].SetFocus
        Me![frmNewProduct]![cmbVendor].SetFocus
0
thenelsonCommented:
You also need to set focus to the form before setting focus to the control:
        Me![ProductDesc].Undo
        Me.Dirty = False
        Forms![frmNewProduct].SetFocus
        Forms![frmNewProduct]![cmbVendor].SetFocus

If [frmNewProduct] is a subform, you can use:
        Me![ProductDesc].Undo
        Me.Dirty = False
        Me![frmNewProduct].SetFocus
        Me![frmNewProduct]![cmbVendor].SetFocus
0
thenelsonCommented:
<Adding:   Me.Dirty = False   -> Run-time error #3058 Index or primary key cannot contain a null value.>

change
        Me.Dirty = False
to
        Me.Undo
0
Rey Obrero (Capricorn1)Commented:
me.undo will clear all the entry you made, are you sure you want to do this?
0
Chi Is CurrentAuthor Commented:
OK -  The statement now reads:

    If IsNull(Forms![frmNewProduct]![cmbVendor].Value) Then
        MsgBox "First enter a VENDOR!", vbCritical, "No Vendor"
        Cancel = True
        'Me![ProductDesc].Undo
        'Me.Dirty = False
        Me.Undo
        Forms![frmNewProduct].SetFocus
        Forms![frmNewProduct]![cmbVendor].SetFocus
        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!
0
Rey Obrero (Capricorn1)Commented:
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?
0
Rey Obrero (Capricorn1)Commented:
like what i said in my first post
<better if you can upload the db..>
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You can't Set Focus to any control or set the value of any control in a Before Update event.

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chi Is CurrentAuthor Commented:
'Bout sez it all.  Thank you!  Jacob
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"'Bout sez it all. Thank you! Jacob"

You are welcome ...

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.