Hi there,
I have a form with a subform on it. The parent form is literally parents, and then the subform is their children that belong to that parent based on the ParentID. Pretty simple stuff.
I've created my own navigation buttons on the subform using some code I found online, and also a line of text that automatically fills in "Child x of y". I want to do the same for the parent form, so I've put the code, like in the child form, in the Form_Current event. When I add new children in the children subform, there are absolutely no problems, it works fine. However, when I try and add a parent, it comes up with an error within the subform Form_current event, possibly because when you add a new parent there is no child associated with it, and therefore there is no recordset to play with.
This code exists in both forms on the Form_Current event. When I click on the 'add parent' button, it picks up the following lines with the subform when its running the code...
It throws up "Run-time error '3201': No Current Record."
I'm sure this must be a relatively easy thing to do, but because I'm not clever enough to have written the code myself, I'm not sure how to approach the problem!
Thanks for your help in advance.
David.
I have a form with a subform on it. The parent form is literally parents, and then the subform is their children that belong to that parent based on the ParentID. Pretty simple stuff.
I've created my own navigation buttons on the subform using some code I found online, and also a line of text that automatically fills in "Child x of y". I want to do the same for the parent form, so I've put the code, like in the child form, in the Form_Current event. When I add new children in the children subform, there are absolutely no problems, it works fine. However, when I try and add a parent, it comes up with an error within the subform Form_current event, possibly because when you add a new parent there is no child associated with it, and therefore there is no recordset to play with.
Code:
Private Sub Form_Current()
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
If Me.CurrentRecord > lngCount Then
lngCount = lngCount + 1
End If
Me.ChildCounter = "Child " & Me.CurrentRecord & " of " & lngCount
If lngCount = 1 Then
Me.First.Enabled = False
Me.Previous.Enabled = False
Me.Next.Enabled = False
Me.Last.Enabled = False
Else
Me.First.Enabled = True
Me.Previous.Enabled = True
Me.Next.Enabled = True
Me.Last.Enabled = True
End If
If Me.CurrentRecord = 1 Then
Me.First.Enabled = False
Me.Previous.Enabled = False
Else
Me.First.Enabled = True
Me.Previous.Enabled = True
End If
If Me.CurrentRecord = lngCount Then
Me.Next.Enabled = False
Me.Last.Enabled = False
Else
Me.Next.Enabled = True
Me.Last.Enabled = True
End If
End Sub
This code exists in both forms on the Form_Current event. When I click on the 'add parent' button, it picks up the following lines with the subform when its running the code...
Code:
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
It throws up "Run-time error '3201': No Current Record."
I'm sure this must be a relatively easy thing to do, but because I'm not clever enough to have written the code myself, I'm not sure how to approach the problem!
Thanks for your help in advance.
David.