Before Update Event + Form add mode

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with certain code in the Before_Update_event.
If the form in add mode it ignores this code. How to solve this problem

Thank you & best regards
 
A form does not ignore the procedure in the form's BeforeUpdate event just
because the form is in "Add" mode. There must be some error occurring that
doesn't allow the form's BeforeUpdate event to occur, or the code itself is
stopping because of an error or of how the code is written.

You'll need to give us more details about the code, your form's setup, etc.
 
Thank you for your reply

I have this code in the Before Update event

If Me.Dirty Then
If Me.SaveCH = True Then
If IsNewRecord = True Then
GoTo Lastline
Else
DoCmd.OpenForm "frmcomments", acNormal
Forms!frmcomments!tableset.Value = 1
Exit Sub
End If
Else
Cancel = True
Exit Sub
End If
Lastline: WriteTempTable
End If

This code works fine if form is in edit mode. frmcomments is opend
When form is in add mode, it goes to Lastline ---(which is OK)
However when the form is opened again in edit mode ,after add mode
(frmcomments should open) the code doesn't run and it goes directly to
Lastline.
By debbuging
I found that IsNewRecord=true if the form is opened in edit mode after add
mode.

Please Help
Thank you and best Regards
 
Didn't get chance to look at this tonite... I'll post a reply tomorrow.
Sorry for the delay.
--

Ken Snell
<MS ACCESS MVP>


Bassel said:
Thank you for your reply

I have this code in the Before Update event
< snipped >
 
I don't understand the context in which this code will be run -- I am
gleaning an understanding that the form in which this code exists is being
opened in either an Add more or an Edit mode, and that the code does what
you want when the form is opened in Edit mode but does not do what you want
when the form is opened in Add mode, is this right?

As I read the code, assuming that you've entered some data into one or more
controls on the form when it's been opened in Add mode, the code will most
likely always go to Lastline labeled code step because a form in Add mode
will always be at a new record (I assume that IsNewRecord is some
user-defined function that is testing for whether the form is at a new
record? I usually just use
If Me.NewRecord = True Then
for such tests). So, in that case, the frmComments form will not be opened.

Also, it appears that the data on the first form are never explicitly saved
before you open frmComments form. If the frmComments form is using data from
a table that is being populated by the first form, that may lead to the
frmComments not showing the newly entered/edited data initially, if that
were your intent. So I suggest that you add a step to the code to save the
data:
If IsNewRecord = True Then
GoTo Lastline
Else
' explicitly save the data on this form before
' opening frmComments form
Me.Dirty = False
DoCmd.OpenForm "frmcomments", acNormal
Forms!frmcomments!tableset.Value = 1
Exit Sub
End If

If this still isn't addressing your question or problem, please post more
details about the context and purpose for this first form -- why do you open
it, what does the user do on the form, what purpose does frmComments have
and how is it related to what is done on the first form, when would you open
the first form in Add mode versus Edit mode, etc.
 

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

Back
Top