Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 23rd, 2003, 08:53 PM
prainey prainey is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 prainey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question rs.MoveLast appears to not be consistant

Hi Guys, im new to this forum, and have a question to ask, many thanks.

Im using the rs.MoveLast in an app and find that it is not consistant with actually "moving to the last record set" every single time consistantly.

(eg: on say 45 entries, it appears ok then on the 46th entry it duplicates the 45th entry again. and again. Sometimes the problem may happen earlier or later than this entry)

The DataBase Table itself "Work Orders" contains a number which seems to duplicate itself after a certain amount of time.

Does the problem exsit in the VB app or the DataBase Table itself?

Here is the vb code..

---------------------------------------------

'Open up the Work Order DataBase Record Set
Set rs = db.OpenRecordset("Work Orders")

'Move to the Last DataBase Record Set
rs.MoveLast

'Add in a new ARCentre DataBase Record Set
rs.AddNew

'Set the Entry Record Fields to the DataBase Record Set
rs!RMANumber = txtOrderReturnMaterialsAuthorisationNumber.Text
rs!DistributorName = txtOrderDistributor.Text
rs!DistributorCustomerNumber = txtOrderDistributorNumber.Text
rs!PurchaseOrderNumber = txtOrderPurchaseOrder.Text
rs!DistributorEndUser = txtOrderDistributorEndUser.Text
rs!WorkTypeRequested = cboOrderWorkType.Text
rs!PartNumber = txtOrderCatalogueNumber.Text
rs!PartDescription = txtOrderCatalogueDescription.Text
rs!AdditionalInformation1 = txtOrderWorkRequestComments1.Text
rs!AdditionalInformation2 = txtOrderWorkRequestComments2.Text
rs!SerialNumber = txtOrderSerialNumber.Text
rs!FreightOption = cboOrderFreightOption.Text
rs!Pricing = txtOrderPrice.Text
rs!GST = txtOrderGST.Text
rs!SubTotal = txtOrderSubTotal.Text
rs!ShippingAddressforReturnGoods = txtOrderShipppingAddress.Text
rs!ShippingStateforReturnGoods = cboOrderShippingState.Text
rs!ShippingPostcodeforReturnGoods = txtOrderShippingPostCode.Text
rs!ShippingContactNameforReturnGoods = txtOrderShippingContactName.Text
rs!ShippingPhoneforReturnGoods = txtOrderShippingContactPhoneNumber.Text

'Update the DataBase Record Set
rs.Update

'Close the DataBase Record Set
rs.Close

-------------------------------------------------------

Many Thanks, Peter.

Reply With Quote
  #2  
Old October 26th, 2003, 12:03 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Hi!Peter!I think it is impossible that the DataBase Table itself "Work Orders" contains a number which seems to duplicate itself after a certain amount of time. But i haven't found the mistake in your code...Plz tell me your table data structure??..It maybe has some thread to find the reason..

Reply With Quote
  #3  
Old October 26th, 2003, 12:41 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,713 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 23 h 57 m 59 sec
Reputation Power: 688
Without an ORDER BY in the select sql, there is no guarantee the last displayed record in a table or recordset is in fact the last record that was inserted.

Reply With Quote
  #4  
Old October 26th, 2003, 03:44 PM
prainey prainey is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 prainey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How is ORDER BY in the select sql, performed

Hi Doug, many thanks for the reply.

This does seem like the problem i am experiencing

How is ORDER BY in the select sql, performed within Access or can it be done in the VB code itself?

Could you please provide an example.

Many Thanks,

Peter

Reply With Quote
  #5  
Old October 26th, 2003, 07:41 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,713 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 23 h 57 m 59 sec
Reputation Power: 688
I'm not sure with DAO. You'll want to use a select statement such as SELECT * FROM [Work Orders] ORDER BY someField

Reply With Quote
  #6  
Old October 26th, 2003, 11:49 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Doug G is right!

Reply With Quote
  #7  
Old October 27th, 2003, 01:22 AM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
this problem is often tied to the fact that the Query isn't in the exact order expected, so after adding a new record the last (46th) was actually the 45th, which got bumped down since the new record showed up in the middle somewhere.
Often this can be sidestepped by using an Order By parameter to the query, specifying an AutoIncrementing ID field (counter) or insertion timestamp field (if they exist) or adding a new field which does this.

If "Work Orders" is a query in access, all you need to do is go into the query window and add the appropriate ordering under the column name (if you were to have used * for the columns, add another with the specific column - in this case I am guessing RMAnumber is either itself or based on an automatically incrementing counter field). If it were a "calculated" field, you need the counter field upon which it is based...
If you are writing the SQL code yourself, then Doug G has the right idea.

Reply With Quote
  #8  
Old October 27th, 2003, 04:11 PM
prainey prainey is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 prainey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Guys, Many Thanks for the feedback,

Yes this seems the way to go, however the problem is the VB Code writes directly to a Table instead of a Query.

This table being the "Work Orders" Table (See attachment)

As far as i'm aware, there is no way to sort a field as ascending order within a table consistanly?

I guess the only thing i could do would be to set up another field in the Work Orders Table called "Autonumber" and use the Autonumber system access provides?

Any ideas?

Thanks,
Attached Files
File Type: zip work orders tabledesign view.zip (55.0 KB, 186 views)

Reply With Quote
  #9  
Old October 27th, 2003, 11:35 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,171 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 37 sec
Reputation Power: 110
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
that seems strange, any ODBC compliant ActiveX should accept a SQL Statement like "Select * from Sometable Order By SomeField Asc"
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #10  
Old October 28th, 2003, 12:33 AM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Quote:
Originally posted by prainey ...I guess the only thing i could do would be to set up another field in the Work Orders Table called "Autonumber" and use the Autonumber system Access provides?...
I would definitely avoid calling it Autonumber and use something like WorkID that definitely can't confuse Access seeming to be a reserved term...

Reply With Quote
  #11  
Old October 28th, 2003, 11:25 AM
randomblink randomblink is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Just this side of hell, Tulsa, Oklahoma...
Posts: 13 randomblink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 32 sec
Reputation Power: 0
Send a message via ICQ to randomblink Send a message via AIM to randomblink Send a message via Yahoo to randomblink
Just another Tip

You also might try AVOIDING naming your tables with Spaces in the name...

Also a naming convention will help to avoid problems if you have queries with the same names as tables...

For instance...
Name your 'Work Orders' table this: tbl_WorkOrder

this way you COULD create a query and call it: qry_WorkOrder
and you wouldn't have to worry about naming hassles...

Just my two cents...
good luck...

Reply With Quote
  #12  
Old October 28th, 2003, 11:55 AM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 485 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 42 sec
Reputation Power: 5
What I suggest you do is to change your table a little bit like people told you before.

you could just add a No_Order that would be the primary key, and you set it up as an increment. That's mean it will always be in a order where you have inserted them and when you say move last it's goes to the last one, and when you ask him to make a new one then he will add a new row under the last row.

I hope you understand me.

But becareful how you use it and why. It's not the best way to solve problems but sometimes it's just easier.
exemple : The project I am working on right now, the guy before added an incremented primary that you don't need to anywhere. Instead of using a VP number that my program use everywhere and that is kinda the primary key in the program but not in table. It's just that I can do querys etc... using it but problems happens when I try to remove or add or modify directly. Soo I needed to do more new functions etc... that just made the program slower.

Soo I say be careful when you will do it. But I think it's the best way to solve your problem right now.

Reply With Quote
  #13  
Old October 28th, 2003, 04:06 PM
prainey prainey is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 prainey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Incrumenting seems to now be fixed

Hi Guys,

Many thanks to the USA guys for there help, and the other support guys as well.

OK, i think it is now fixed! - time will tell!

OldJacques and the other guys were pretty much on the ball with the problem, all the Table required was an "AutoIncrument Field", using the AutoNumber in Access.

And i have called it "WorkOrders" (seeing this represents how many WorkOrders were created) as a name instead of AutoNumber which incruments on every new record insertion.
(See Attached)

After testing with 43 new entries from my VB app, not one entry missed a beat, all entered into the table one after another in accending numerical order.
(See Attatched)

It appears the AutoNumber in Access is "forcing" the next new record to the end of the record set! - great just what i was after!

And there can be now no duplication because you can't have a primary key field "autonumber" duplicate.

I'll keep testing, but for now it seems OK.
(If anyone else has a similair problem, looks like this is the fix!)

Cheers,

Pete.
Attached Files
File Type: zip autoincrument field included.zip (73.8 KB, 217 views)

Reply With Quote
  #14  
Old October 28th, 2003, 05:36 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,713 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 23 h 57 m 59 sec
Reputation Power: 688
Quote:
And there can be now no duplication because you can't have a primary key field "autonumber" duplicate.

Over time, this may not always remain true. You really should order your resultset to guarantee your idea of the "last" record is consistent.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > rs.MoveLast appears to not be consistant


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread