473,388 Members | 1,383 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,388 software developers and data experts.

MoveFirst seems to be MovingMiddle.... Please help

I'm stumped, and could really use an expert's advice. I have two tables: raw and matrix -- both are sorted ascending on the first row (if that matters). raw has 607,513 rows and 4 fields. Matrix has 383,078 rows and 27 fields. When I run the following code with matrix as my recordset, it moves to the first row, and picks off the value in the first field, displaying it in the messagebox (as desired)... but when I run it with raw it displays the first field value of row 249 -- not the first record. If I try to use a for i= 0 to 248 with MovePrevious, it bombs when i=1. Can anyone think of why it would not move to the first record with one particular table? How can this be fixed? Thanks in advance!


Sub main_Base()

Dim mydb As DAO.Database
Dim raw As DAO.Recordset

Set mydb = CurrentDb
Set raw = mydb.OpenRecordset("2_Base_Demands_by_Week")

raw.MoveFirst
MsgBox raw(0)
raw.Close

End Sub
Jun 24 '10 #1
2 1563
gershwyn
122 100+
The data in a table is not stored in any particular order. Sorting it by a certain field will change how it is displayed, but won't change the order the records are accessed in a VBA recordset. For that, we need to set an index.

Open the underlying table in design view and add a new index on the field (or fields) that you want the order based on. Then set the index property of the recordset before you call MoveFirst. Something like this:

Expand|Select|Wrap|Line Numbers
  1. Set raw = mydb.OpenRecordset("2_Base_Demands_by_Week")
  2. raw.Index = "myIndex"
  3. raw.MoveFirst
If needed, you can also create the index programatically - lookup the TableDef.CreateIndex method in help. I don't use it much, so the code example will probably be easier to follow than my explanation.
Jun 24 '10 #2
Thanks gershwyn!
Jun 24 '10 #3

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

Similar topics

1
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if...
8
by: matt.sus | last post by:
This has been driving me crazy for days: IF ANYONE CAN HELP FIX THE HTML BELOW, PLEASE HELP! (please email me at matt.sus@gmail.com - or reply here) i am trying to load up a random background...
2
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
1
by: Steve | last post by:
Hi, I've asked this question a couple of times before on this forum but no one seems to be nice enough to point me to the right direction or help me out with any information, if possible. Please...
6
by: Rylios | last post by:
I am trying to make a very basic text editor using a linked list, fstream, sorting... This is what i have so far...
9
by: Andreas Vinther | last post by:
I have a small piece of code that compiles but does not perform like I want it to. This code works: ---------------- void *y0; void *y1; void *y2; void *y3;
5
by: AAJ | last post by:
Hi all FIRST THE BORING BITS....... I normally use a Database layer, a Business layer and a GUI layer. The GUI uses an Object data source to bind to the Business layer which in turn binds...
9
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
4
by: Tonio Tanzi | last post by:
I have the following problem in a Win 2000 Server + SQL Server 2000 environment and I hope somewhat can help me to resolve it (after many days of useless attempts I am desperate). In my database...
2
by: e4r3i5c | last post by:
Hi, i have a problem with my ssdbgrid in vb6. the task is to find and highlight selected row in the grid.. . . Is there anyone can help me with this problem?.. my code below is to select the specfic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.