The first thing that jumps out at me is that you are trying
to close the RecordsetClone. I don't know what this may or
may not do, but it is certainly wrong. Since you did not
open that recordset, you can not close it.
The subform code is trying to manipulating its parent's
records, which doesn't make sense to me. Actually, I would
think it would be better all the way around if you just set
all these form's AllowAdditions property to No. This will
disable the new record button on the navigation bar and you
can do away with all these complications.
If the data is read only, you may want to set the AllowEdits
and and AllowDeletes properties to No as well.
--
Marsh
MVP [MS Access]
Jac said:
What I am doing with the code is as follows (see code below).
I have a parent form with the navigation bar displayed. The records in that
system can only be inserted from occurrences in a DB2 system. The user cannot
type in some new record. So there is a special button (Search) that allows
this operation.
But when the user clicks on the New record button on the navigation bar, I
want to display a message and return to the last record. My code works fine
in the current event of thay main form.
Now, on that main form, there is a subform with the children displayed.
Those children must also be inserted via a special procedure. So I added a
button (New follow up) to do that job. So when the user clicks on the new
record button on the child form, I also want to display a message and display
the last record. This operation works fine now but it didn't work when the
code was in its current event procedure.
Since this subform contains another level of child (grand-children), I tried
to put the code in that (sub)subform and it worked (with minor adjustments).
On the subform, the navigation buttons are displayed, but on the
(sub)subform, they are not.
Here is the code for both procedures:
' **********************************************************
Private Sub Form_Current()
' The main form, the parent (actually the grand-parent).
Dim rst As Recordset
If Me.NewRecord Then
strMsg = "No insert possible with this button." & _
vbCrLf & "Use the Search button in the top of the form."
intStyle = vbExclamation + vbOKOnly
intRéponse = MsgBox(strMsg, intStyle, strcTitre)
Set rst = Me.RecordsetClone
With rst
.MoveLast
Me.Bookmark = .Bookmark
.Close
End With
Set rst = Nothing
End If
End Sub
' **********************************************************
Private Sub Form_Current()
' The child form inserted in the child (actually the grand-child).
Dim rst As Recordset
If Me.Parent.NewRecord Then
strMsg = "No insert possible with this button." & _
vbCrLf & "Use the New follow up button in the top of the form."
intStyle = vbExclamation + vbOKOnly
intRéponse = MsgBox(strMsg, intStyle, strcTitre)
Set rst = Me.Parent.RecordsetClone
With rst
.MoveLast
Me.Parent.Bookmark = .Bookmark
.Close
End With
Set rst = Nothing
End If
End Sub
' **********************************************************
Hope this clarifies the situation for you. Right now, it works so I do not
need to correct anything.
The code is actually written in french. I changed some messages to make it
clearer.
Thanks for your concern and comments.