Connecting Tech Pros Worldwide Help | Site Map

How to sort table with VBA

Troy
Guest
 
Posts: n/a
#1: Jul 17 '06
Public Sub test()

DoCmd.OpenTable ("OSM Table 1")

End Sub

Amazingly, I've gotten this far, now I am wondering how to sort the
database in ascending order according to field called [Meal Total] and
then select the first record. It's all got to be in VBA, can anyone
help?

Thanks

Bob Quintal
Guest
 
Posts: n/a
#2: Jul 18 '06

re: How to sort table with VBA


"Troy" <TroyDDaniels@gmail.comwrote in
news:1153171240.846503.122570@b28g2000cwb.googlegr oups.com:
Quote:
Public Sub test()
>
DoCmd.OpenTable ("OSM Table 1")
>
End Sub
>
Amazingly, I've gotten this far, now I am wondering how to
sort the database in ascending order according to field called
[Meal Total] and then select the first record. It's all got
to be in VBA, can anyone help?
>
Thanks
>
You can't sort a table. You make a query on the table and use that
query instead of the table.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

DFS
Guest
 
Posts: n/a
#3: Jul 18 '06

re: How to sort table with VBA


Troy wrote:
Quote:
Public Sub test()
>
DoCmd.OpenTable ("OSM Table 1")
>
End Sub
>
Amazingly, I've gotten this far, now I am wondering how to sort the
database in ascending order according to field called [Meal Total] and
then select the first record. It's all got to be in VBA, can anyone
help?
>
Thanks
Do


You can mess around and do it like this:

DoCmd.OpenTable "Table1"
DoCmd.GoToControl "field name"
DoCmd.FindRecord "VALUE", acAnywhere, False, acSearchAll, True, acCurrent
DoCmd.RunCommand acCmdSortAscending
DoCmd.RunCommand acCmdSelectRecord


But like B Quintal says, you should probably just run and open a query on
the table.




Terry Kreft
Guest
 
Posts: n/a
#4: Jul 18 '06

re: How to sort table with VBA


You should not open tables.

You should use a form for data entry and a report for data review.

Either way, you use a query as the recordsource as you can then sort the
data in any way you want.


--

Terry Kreft


"Troy" <TroyDDaniels@gmail.comwrote in message
news:1153171240.846503.122570@b28g2000cwb.googlegr oups.com...
Quote:
Public Sub test()
>
DoCmd.OpenTable ("OSM Table 1")
>
End Sub
>
Amazingly, I've gotten this far, now I am wondering how to sort the
database in ascending order according to field called [Meal Total] and
then select the first record. It's all got to be in VBA, can anyone
help?
>
Thanks
>

DFS
Guest
 
Posts: n/a
#5: Jul 18 '06

re: How to sort table with VBA


Terry Kreft wrote:
Quote:
You should not open tables.
This is bogus advice, I think.

You should open tables if you need to or if you want to. There's certainly
no need to create a form and report for every table in your system, eg just
to edit a small lookup table (or even a large transaction table).
Especially if you "know" your data.


Quote:
You should use a form for data entry and a report for data review.
Why? Though a well-defined form can give you more control and safety, it's
no panacea, and building good validation rules and proper data typing can
aid in entering data directly in tables.


Quote:
Either way, you use a query as the recordsource as you can then sort
the data in any way you want.
Yes. Or you can filter and sort it pretty much any way you want if you open
the table directly.



Quote:
"Troy" <TroyDDaniels@gmail.comwrote in message
news:1153171240.846503.122570@b28g2000cwb.googlegr oups.com...
Quote:
>Public Sub test()
>>
>DoCmd.OpenTable ("OSM Table 1")
>>
>End Sub
>>
>Amazingly, I've gotten this far, now I am wondering how to sort the
>database in ascending order according to field called [Meal Total]
>and then select the first record. It's all got to be in VBA, can
>anyone help?
>>
>Thanks

David W. Fenton
Guest
 
Posts: n/a
#6: Jul 18 '06

re: How to sort table with VBA


"Terry Kreft" <terry.kreft@mps.co.ukwrote in
news:AYacnV-qS7-lDCHZSa8jmw@karoo.co.uk:
Quote:
You should not open tables.
>
You should use a form for data entry and a report for data review.
>
Either way, you use a query as the recordsource as you can then
sort the data in any way you want.
In a report, don't sort your underlying recordsource, but use the
report's grouping and sorting.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Rick Brandt
Guest
 
Posts: n/a
#7: Jul 18 '06

re: How to sort table with VBA


DFS wrote:
Quote:
Terry Kreft wrote:
Quote:
>You should not open tables.
>
This is bogus advice, I think.
>
You should open tables if you need to or if you want to. There's
certainly no need to create a form and report for every table in your
system, eg just to edit a small lookup table (or even a large
transaction table). Especially if you "know" your data.
The advice assumes that the user of a database is not the developer of the
database. No one would dispute that the developer can make entries into
utility tables and/or make administrative corrections to other data directly
in the tables.


--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


Tim Marshall
Guest
 
Posts: n/a
#8: Jul 18 '06

re: How to sort table with VBA


David W. Fenton wrote:
Quote:
In a report, don't sort your underlying recordsource, but use the
report's grouping and sorting.
That's my approach and I prefer to base reports on unordered queries to
cut back on the unnecessary processing I assume takes place with the
order by clause.

But I vaguely recall at some point wasn't/isn't there some report
property one can turn on to accept the sorting done by a query?

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Terry Kreft
Guest
 
Posts: n/a
#9: Jul 18 '06

re: How to sort table with VBA


The OP was talking about writing code to open the table.

This implies that they are writing an app for someone else to use.

Only an idiot or a grossly inexperienced developer would allow users direct
access to base tables.

I believe the OP to be inexperienced.

--

Terry Kreft


"DFS" <nospam@dfs_.comwrote in message
news:X62vg.7545$IB.2736@bignews1.bellsouth.net...
Quote:
Terry Kreft wrote:
Quote:
You should not open tables.
>
This is bogus advice, I think.
>
You should open tables if you need to or if you want to. There's
certainly
Quote:
no need to create a form and report for every table in your system, eg
just
Quote:
to edit a small lookup table (or even a large transaction table).
Especially if you "know" your data.
>
>
>
Quote:
You should use a form for data entry and a report for data review.
>
Why? Though a well-defined form can give you more control and safety,
it's
Quote:
no panacea, and building good validation rules and proper data typing can
aid in entering data directly in tables.
>
>
>
Quote:
Either way, you use a query as the recordsource as you can then sort
the data in any way you want.
>
Yes. Or you can filter and sort it pretty much any way you want if you
open
Quote:
the table directly.
>
>
>
>
Quote:
"Troy" <TroyDDaniels@gmail.comwrote in message
news:1153171240.846503.122570@b28g2000cwb.googlegr oups.com...
Quote:
Public Sub test()
>
DoCmd.OpenTable ("OSM Table 1")
>
End Sub
>
Amazingly, I've gotten this far, now I am wondering how to sort the
database in ascending order according to field called [Meal Total]
and then select the first record. It's all got to be in VBA, can
anyone help?
>
Thanks
>
>

David W. Fenton
Guest
 
Posts: n/a
#10: Jul 19 '06

re: How to sort table with VBA


Tim Marshall <TIMMY!@PurplePandaChasers.Moertheriumwrote in
news:e9ili2$1a0$1@coranto.ucs.mun.ca:
Quote:
But I vaguely recall at some point wasn't/isn't there some report
property one can turn on to accept the sorting done by a query?
I don't know. I just learned a long time ago that sorting the
recordsource was so often a waste of time that I just stopped
trying!

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Closed Thread