Display a specified number of records in a continuous form (1 Viewer)

zelarra821

Registered User.
Local time
Today, 11:09
Joined
Jan 14, 2019
Messages
813
Hello people.

Let's see if you can help me.

I attach a database where I have put the code

DoCmd.GoToRecord , , acLast

in the Form_Load event.

When I enter the form, it appears like this:

ScreenShot001.jpg

That is, it shows me only one record, because it is the last one.

Now, here I pose two questions:

1. Is it possible that instead of showing the last one, it shows the last three?

2. Is it possible to get point 1 after updating a record?

Thank you.
 

Attachments

  • Nuevo Microsoft Access Database.accdb
    1.4 MB · Views: 32

CJ_London

Super Moderator
Staff member
Local time
Today, 10:09
Joined
Feb 19, 2013
Messages
16,612
yes it is possible - you need code to go back 2, 3, whatever records - see this link


or google - plenty of examples out there
 

KitaYama

Well-known member
Local time
Today, 18:09
Joined
Jan 6, 2022
Messages
1,541
1-
DoCmd.GoToRecord , , , DCount("*", "Nombres") - 3

2-
I don't understand your second question.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:09
Joined
May 21, 2018
Messages
8,529
This may interest you
Code:
Option Compare Database
Option Explicit
Dim CmbSexo As New FindAsYouTypeCombo

Private Sub cmboNumber_AfterUpdate()
  FilterForm
End Sub

Private Sub Form_AfterUpdate()
  FilterForm
End Sub

Private Sub Form_Load()
    CmbSexo.InitalizeFilterCombo Me.IdSexo, "Sexo", anywhereinstring, True, True
    Me.cmboNumber = 3
    FilterForm
End Sub

Public Sub FilterForm()
  Dim strSql As String
  Dim numbertoshow As Integer
  Dim TotalRecords As Integer
 
  TotalRecords = DCount("*", "Nombres")
  strSql = "Select * from Nombres Order By idNombre"
  If cmboNumber <> "<All>" And Not IsNull(Me.cmboNumber) Then
     numbertoshow = CInt(Me.cmboNumber)
    Debug.Print TotalRecords - numbertoshow
     If TotalRecords > numbertoshow Then
         strSql = "Select * from Nombres where idNombre NOT IN (Select Top " & (TotalRecords - numbertoshow) & " idNombre from Nombres Order By Idnombre) Order By idNombre"
     End If
  End If
 Me.RecordSource = strSql
 Debug.Print strSql
End Sub

This way you are only displaying X amount of the last records or you can choose All
 

Attachments

  • Nuevo Microsoft Access Database (1).accdb
    1.7 MB · Views: 32

zelarra821

Registered User.
Local time
Today, 11:09
Joined
Jan 14, 2019
Messages
813
Well yes, it interests me and helps me achieve what I want.

Just a very small detail: when you reach the last field of the record in question, it takes you to the first record of the number that you have selected in the drop-down menu. The natural behavior would be to move to the next record. Can this be done? I don't know if I explain myself.

ScreenShot001.jpg
ScreenShot002.jpg
ScreenShot003.jpg
ScreenShot004.jpg

Thanks.
 

Attachments

  • Nuevo Microsoft Access Database (1).accdb
    1.9 MB · Views: 24

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:09
Joined
May 21, 2018
Messages
8,529
How about this where you check that the number of records did not change
Code:
Option Compare Database
Option Explicit
Dim CmbSexo As New FindAsYouTypeCombo
Dim CmbOtraOpcion As New FindAsYouTypeCombo
Dim PreviousCount As Long

Private Sub cmboNumber_AfterUpdate()
  FilterForm
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)
  FilterForm
End Sub

Private Sub Form_AfterUpdate()
  FilterForm
End Sub

Private Sub Form_Load()
    CmbSexo.InitalizeFilterCombo Me.IdSexo, "Sexo", anywhereinstring, True, True
    CmbOtraOpcion.InitalizeFilterCombo Me.IdOtraOpcion, "OtraOpcion", anywhereinstring, True, True
    Me.cmboNumber = 3
    PreviousCount = DCount("*", "Nombres")
    FilterForm True
    
End Sub

Public Sub FilterForm(Optional FirstPass As Boolean = False)
  Dim strSql As String
  Dim numbertoshow As Integer
  Dim TotalRecords As Integer
 
  TotalRecords = DCount("*", "Nombres")
  If PreviousCount <> TotalRecords Or FirstPass Then
     PreviousCount = TotalRecords
     strSql = "Select * from Nombres Order By idNombre"
     If cmboNumber <> "<All>" And Not IsNull(Me.cmboNumber) Then
        numbertoshow = CInt(Me.cmboNumber)
        If TotalRecords > numbertoshow Then
            strSql = "Select * from Nombres where idNombre NOT IN (Select Top " & (TotalRecords - numbertoshow) & " idNombre from Nombres Order By Idnombre) Order By idNombre"
        End If
     End If
    Me.RecordSource = strSql
    Debug.Print strSql
    Me.Recordset.MoveLast
 End If
End Sub
 

zelarra821

Registered User.
Local time
Today, 11:09
Joined
Jan 14, 2019
Messages
813
I just saw the operation itself.

I want to have all the records available and to see the last three. Now I only have the ones I marked in the drop-down menu, in this case, three, so to see all of them, I have to mark them in the drop-down menu. No, this is not what I was looking for. Is what I want possible?

ScreenShot001.jpg

ScreenShot002.jpg

On the other hand, with the change you have made now, you have fixed what it said that it went to the first visible record as long as it did not check the All drop-down menu.

Thank you so much.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:09
Joined
May 21, 2018
Messages
8,529
Code:
Option Compare Database
Option Explicit
Dim CmbSexo As New FindAsYouTypeCombo
Dim CmbOtraOpcion As New FindAsYouTypeCombo
Dim PreviousCount As Long

Private Sub cmboNumber_AfterUpdate()
  moveForm True
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)
  moveForm
End Sub

Private Sub Form_AfterUpdate()
  moveForm
End Sub

Private Sub Form_Load()
    CmbSexo.InitalizeFilterCombo Me.IdSexo, "Sexo", anywhereinstring, True, True
    CmbOtraOpcion.InitalizeFilterCombo Me.IdOtraOpcion, "OtraOpcion", anywhereinstring, True, True
    Me.cmboNumber = 3
    PreviousCount = DCount("*", "Nombres")
    moveform True
   
End Sub

Public Sub moveForm(Optional FirstPass As Boolean = False)
  Dim strSql As String
  Dim numbertoshow As Integer
  Dim TotalRecords As Integer

  TotalRecords = DCount("*", "Nombres")
  If PreviousCount <> TotalRecords Or FirstPass Then
     PreviousCount = TotalRecords
      If cmboNumber <> "<All>" And Not IsNull(Me.cmboNumber) Then
        numbertoshow = CInt(Me.cmboNumber)
        Me.Recordset.MoveFirst
        Me.Recordset.AbsolutePosition = TotalRecords - numbertoshow
        If TotalRecords > numbertoshow Then
        End If
     End If
End If
End Sub
 
Last edited:

zelarra821

Registered User.
Local time
Today, 11:09
Joined
Jan 14, 2019
Messages
813
I must be doing something wrong that I get an error. Here the database
 

Attachments

  • Nuevo Microsoft Access Database (1) - copia.accdb
    1.9 MB · Views: 25

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:09
Joined
May 21, 2018
Messages
8,529
Your On load was wrong. I must have copied something wrong. It called the old filterform not the new moveform. But I added another check anyways.
Code:
Option Compare Database
Option Explicit
Dim CmbSexo As New FindAsYouTypeCombo
Dim CmbOtraOpcion As New FindAsYouTypeCombo
Dim PreviousCount As Long

Private Sub cmboNumber_AfterUpdate()
  moveForm True
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)
  moveForm
End Sub

Private Sub Form_AfterUpdate()
  moveForm
End Sub

Private Sub Form_Load()
    CmbSexo.InitalizeFilterCombo Me.IdSexo, "Sexo", anywhereinstring, True, True
    CmbOtraOpcion.InitalizeFilterCombo Me.IdOtraOpcion, "OtraOpcion", anywhereinstring, True, True
    Me.cmboNumber = 3
    PreviousCount = DCount("*", "Nombres")
    moveForm True
    
End Sub

Public Sub moveForm(Optional FirstPass As Boolean = False)
  Dim strSql As String
  Dim numbertoshow As Integer
  Dim TotalRecords As Integer
  Dim rs As DAO.Recordset
 
 
  TotalRecords = DCount("*", "Nombres")
  If PreviousCount <> TotalRecords Or FirstPass Then
      PreviousCount = TotalRecords
      Set rs = Me.Recordset
      If cmboNumber <> "<All>" And Not IsNull(Me.cmboNumber) And rs.RecordCount > Me.cmboNumber Then
        numbertoshow = CInt(Me.cmboNumber)
        rs.MoveFirst
        Debug.Print TotalRecords - numbertoshow
        rs.AbsolutePosition = (TotalRecords - numbertoshow)
        If TotalRecords > numbertoshow Then
        End If
     End If
 End If
End Sub
 

Users who are viewing this thread

Top Bottom