Query Record Number

tobeon

Board Regular
Joined
Jan 26, 2003
Messages
81
Hello

how could you make a query so all recordsa above a specific record number is displayed

(the actual record number not an autonumber field)

thank you for any help youcan give

p.s
this is quite urgent
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
The answer depends on how flexible you need the query to be for production use. If the number to test against changes, then you'll want to use VBA to define a query as needed.

I'm making an assumption that you're probably using something like a form and asking users to type in a value then hitting a command button to show your query.

Inserting this into the _Click() event...

Call MakeQry(Forms!formName.controlName)
DoCmd.OpenQuery qryName, acReadOnly

Function MakeQry(ByVal qryname As String, ByVal yourvalue As Long)
Dim dbs As DAO.Database
Dim strSQL As String

Set dbs=CurrentDB()

strSQL = "SELECT * FROM tbl1 WHERE tbl1.fld1 > " & yourvalue & ";"

DoCmd.DeleteObject acQuery,qryName
Set qdf = dbs.CreateQueryDef(qryName,strSQL)

Set dbs = Nothing
End Function

This actually defines the query.
A simpler approach would be to avoid the need to delete/define a query
and use DoCmd.RunSQL

Function MakeQry(ByVal qryname As String, ByVal yourvalue As Long)
Dim dbs As DAO.Database
Dim strSQL As String

Set dbs=CurrentDB()

strSQL = "SELECT * FROM tbl1 WHERE tbl1.fld1 > " & yourvalue & ";"

DoCmd.RunSQL strSQL

Set dbs = Nothing
End Function

The difference is, your needs. Do you need to use the query elsewhere?

Mike
 
Upvote 0
You can also try a Top Values query. If you don't want to base it on a field in your table like you said in your request, just start a new query, and in the box (small drop-down) at the top (in the Query Design toolbar) where it says "All", just type in the number of records that you want to show.

HTH,

Russell
 
Upvote 0

Forum statistics

Threads
1,221,533
Messages
6,160,382
Members
451,644
Latest member
mkotas

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top