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.