473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problem sorting tables in visual basic

Hi,

I am using visual basic in access 2003 and am having a problem with sorting tables which I can't seem to find a solution to, and was hoping that someone might be able to help.

I have a table containing policy numbers and various bits of information about each policy. It is necessary to go through the table in policy order and do various calculations to each row.

So, I have used an SQL query to create a copy of the table sorted by policy number as follows:

Dim STR As String

STR = " SELECT Policy.* INTO PolicyCopy FROM Policy ORDER BY PolicyNumber; "
DoCmd.RunSQL (STR)


I now open the table PolicyCopy as follows:

Dim db As Database
Dim PolicyRecordset As Recordset

Set db = CurrentDb
Set PolicyRecordset = db.OpenRecordset("PolicyCopy", dbOpenTable)


Then I go through the PolicyRecordset by using Movefirst and Movenext's.

However, sometimes the program will crash because the PolicyCopy table is not in the correct order. Sometimes the top few rows, usually about a couple of hundred, will be dumped into the middle of the table. I wondered if anyone knew how to get around this problem

Many thanks
Nov 11 '06 #1
3 1320
willakawill
1,646 1GB
Hi,

I am using visual basic in access 2003 and am having a problem with sorting tables which I can't seem to find a solution to, and was hoping that someone might be able to help.

I have a table containing policy numbers and various bits of information about each policy. It is necessary to go through the table in policy order and do various calculations to each row.

So, I have used an SQL query to create a copy of the table sorted by policy number as follows:

Dim STR As String

STR = " SELECT Policy.* INTO PolicyCopy FROM Policy ORDER BY PolicyNumber; "
DoCmd.RunSQL (STR)


I now open the table PolicyCopy as follows:

Dim db As Database
Dim PolicyRecordset As Recordset

Set db = CurrentDb
Set PolicyRecordset = db.OpenRecordset("PolicyCopy", dbOpenTable)


Then I go through the PolicyRecordset by using Movefirst and Movenext's.

However, sometimes the program will crash because the PolicyCopy table is not in the correct order. Sometimes the top few rows, usually about a couple of hundred, will be dumped into the middle of the table. I wondered if anyone knew how to get around this problem

Many thanks
Hi. You have the answer really. Just need to put the two statements together.

Set PolicyRecordset = db.OpenRecordset("SELECT * FROM Policy ORDER BY PolicyNumber")

The table type recordset is default.

And away you go :)
Nov 11 '06 #2
Hi. You have the answer really. Just need to put the two statements together.

Set PolicyRecordset = db.OpenRecordset("SELECT * FROM Policy ORDER BY PolicyNumber")

The table type recordset is default.

And away you go :)

Thats wonderful, thanks very much
Nov 11 '06 #3
I Think into Statement Does Not Allow Order By Class
So please remove Order by policyNumber statement

STR = " SELECT * INTO PolicyCopy FROM Policy "

Dim db As Database
Dim PolicyRecordset As Recordset
Set db = CurrentDb
Set PolicyRecordset = db.OpenRecordset("select * from policycopy order by policynumber")

Thanking U
R.Jayaprakash
Nov 12 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
7
by: Foxster | last post by:
in access i have two tables (tblplayer, tblpoints) in tblplayer i have field totalpoint (number) in tlbpoints i have field pointgame (number) the two files are related via idplayer now i made a...
7
by: manning_news | last post by:
I've got a report that's not sorting correctly. I build a SQL statement and assign it to the recordsource in the Open event, sorting the data the way the user chooses. The user can choose up to 3...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
2
by: Cindy Lee | last post by:
I get my data from a basic xml file and make a datatable, and then bind it to the gridview. I think it's not sorting or dataformatString correctly because it thinks it's a string and not a number....
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.