Select rows to view

mikekal

Member
Local time
Today, 13:53
Joined
Jun 24, 2017
Messages
114
How can make a combobo with values 1,2,3,4,5............... and when select them i can view only those rows.When select 4 i can view 4 rows.When select 7 i can view 7 rows
 
Gonna need a bigger picture. When you select "4" which 4 rows do you expect to see? Where do you expect to see them? Have a copy of your database for reference?
 
That my database.On the left combobox if select a number i can view only those lines.
 

Attachments

  • Screenshot (21).png
    Screenshot (21).png
    123.2 KB · Views: 108
Like that
 

Attachments

  • Screenshot (22).png
    Screenshot (22).png
    104.9 KB · Views: 109
Generally speaking, use the value from your combo when building SQL that the form is based on. Use it with the TOP predicate and the appropriate sorting.

SELECT TOP 4 Field1, ...
FROM TableName
WHERE ...
ORDER BY ...

Getting the "4" from your combo.
 
Maybe im not understand.I want to view those rows that the combobox shows.
 
If you mean that when you choose 7, you want to see 7 rows, then I'd use what I mentioned. If you mean that when you choose 7, you want to see records where a given value is 7, then perhaps:


But based on your second picture, you want to view a quantity of rows matching the value in the combo. That's easy, but then getting the "next" 7 (or whatever value was chosen in the combo) gets trickier. I feel like I've seen that done but can't recall how offhand.
 
So you want to see X records per page. And the buttons up top would be what page. The only problem is you will have to write code for the correct amount of buttons. I will assume you can do the code to modify the buttons and show the correct amount of pages, and scroll pages. I did not do that part.

If you want to see page 3 where you are showing 20 records per page then
page = 3
perPage = 20
and you want to see the Top 20 from some query Not In the Top (40) because the top 40 where on page 1 and 2.

This is untested by something like

Code:
private page as integer
private perpage as integer

Code:
public CmboCount_AfterUpdate
  if not isNull me.CmboCount then
    perPage = me.cmboCount
    page = 1
    'some code here to set focus to button 1
    SelectRecords
end if


Code:
Private sub SelectRecords()
  dim strSql as string
  dim notIn as integer
  if page = 1 then
    strSql = "Select Top " & perpage & " * from someQuery"
  else
    notIn = (Page - 1) * perpage
    strSql = "Select Top " & perpage & " * from somequery where someID NOT in (Select Top " & NotIN & " someID from somequery"
  end if
  me.rowSource = strSql
end sub

I will assume you have 6 buttons and code to change the caption of the buttons

Code:
Private sub BtnA_Click()
  'same code for B,C,D,E,F
  'you will have to write code to change the button captions as you scroll
  page = cint(btnA.caption)
  selectRecords
end sub
 
Ok thank you
In the begining of my pagination form the code is like that:

Option Compare Database
Option Explicit
Private Const lRecPerPage As Long = 32


Private Sub cmd_page_1_Click()
Call Paginate(Me.cmd_pagination_1)
End Sub

Private Sub cmd_page_10_Click()
Call Paginate(Me.cmd_pagination_10)
End Sub

Private Sub cmd_page_2_Click()
Call Paginate(Me.cmd_pagination_2)
End Sub

Private Sub cmd_page_3_Click()
Call Paginate(Me.cmd_pagination_3)
End Sub

Maybe whith combobox can change when i want the "lRecPerPage As Long = 32"
 
This is pretty close. I have not coded the buttons to scroll to additional pages but 1 to 4 work. However, this subquery (Not in) is slow. You may be able to write this as a outer join instead.
 

Attachments

Thank you very much.That i was want.Sorry for bad english.Many thanks from Greece
 

Users who are viewing this thread

Back
Top Bottom