MS Access DoCmd.GoToRecord doesn't work after Form Requery

mnish

New member
Local time
Today, 19:08
Joined
Sep 29, 2022
Messages
2
I have a main form and a sub form.
On the main form I have some text boxes and two buttons to add records to a table table1.
The sub form is a continuous from that shows the content of table1, onLoad the sub form show the last 10 records, and the rest of the records can be seen by scrolling up.
What I am trying to do is whenever a new record is added the sub form must be updated and after that show the last 10 records again.
Here how I am doing this but does not work
Code:
Public Sub Update_From()
    Me.Form.Requery
 End Sub

Public Sub Update_Goto()
    Update_From
    Dim ID As Long
    ID = (DMax("ID", "details"))
    If ID < 10 Then
       ID = 1
    Else
        ID = ID - 10
    End If
    DoCmd.GoToRecord , , acGoTo, ID
 End Sub

Both functions work individually, but when the Update_form is called and then the DoCmd.GoToRecord is called, the DoCmd.GoToRecord part does not work, i.e. the form shows the first record instead of the specified ID.
I appreciate any help.
 
maybe you can do an "alternative"
Code:
Public Sub Update_From()
    Me.Requery
 End Sub

Public Sub Update_Goto()
    Update_From
    With Me.Recordset
        If .RecordCount > 10 Then
            .MoveLast
            .Move -9
        End If
    End With
    'Dim ID As Long
    'ID = (DMax("ID", "details"))
    'If ID < 10 Then
    '   ID = 1
    'Else
    '    ID = ID - 10
    'End If
    'DoCmd.GoToRecord , , acGoTo, ID
 End Sub
 
That works great. I never knew about .Move x. Doesn't have the drawbacks identified in other posting.
 
Public Sub Update_Goto()
Update_From
With Me.Recordset
If .RecordCount > 10 Then
.MoveLast
.Move -9
End If
End With

End Sub
[/CODE]
Thanks a lot! your solution dit the trick!
 

Users who are viewing this thread

Back
Top Bottom