UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Move backward in records    
 
   
bis2k
post Jan 6 2010, 01:01 PM
Post #1

UtterAccess Guru
Posts: 506



I have a form of products, with a subform that lists its components.

Some componets can also be made from other components.

I created code so if I double-click on a componet in the subform, the main form changes to display that record along with its components. On double-click I store the ID from the main form as [OLDID]. Then I have an UP button that finds the record of the [OLDID].

My problem is that sometimes I want to go down 2 or 3 levels. Is there a way to store OLDID1, OLDID2 & OLDID3. Then as I click the UP button I would display product records in reverse until I wind up back on the original Product?

Thanks
Larry
Go to the top of the page
 
+
doctor9
post Jan 6 2010, 01:28 PM
Post #2

UtterAccess VIP
Posts: 9,430
From: Wisconsin



Larry,

This is usually referred to as a "stack" in programming circles. If you've ever encountered a "stack overflow" error, you've tried to add more data than was allocated for the "stack".

Here's one strategy:

1. Create a table (local to the frontend, NOT shared on the network) to store your "stack":

tblStack
StackID [PK, integer]
intComponentID [FK to the primary key value of your components table]

2. When the main form first opens, clear out the tblStack table.

3. On the double-click event for the subform's control, grab the primary key value from the main form, and create a new record in the tblStack table. This record will contain:
3a. StackID - an incrementing value that tracks the order in which the components were stored. Use the DMax and Nz functions to determine the value for StackID; if the table is empty, start with "1". Otherwise, find the highest value and add one.
3b. intComponentID - the primary key value from the main form

Once this is done, you can perform the VBA code you've already written to view the new component record.

4. On the OnClick event for the UP button, grab the intComponentID value from the record with the highest value for StackID. (If the table's empty, do nothing.) Use the intComponentID value to view the matching record in the main form. Delete the record you just looked up in the tblStack table.

I think that's about it.

Hope this helps,

Dennis
Go to the top of the page
 
+
ace
post Jan 6 2010, 01:33 PM
Post #3

UtterAccess VIP
Posts: 5,283
From: Upstate NY, USA



An array would be a reasonable way to store values in a sequence.
You can iterate through an array in either direction.

A VBA Collection might be a better choice since they make it much easier
to add or remove an item.

Maybe even go so far as to implement a stack.
Go to the top of the page
 
+
bis2k
post Jan 6 2010, 01:43 PM
Post #4

UtterAccess Guru
Posts: 506



How would I create an Array or a VBA collection?

Could you provide an example?

Thanks
Go to the top of the page
 
+
ace
post Jan 6 2010, 01:51 PM
Post #5

UtterAccess VIP
Posts: 5,283
From: Upstate NY, USA



Follow the implementing a stack link in my post.

The example code there uses an array to build a Stack class.
Nothing I post will make it any more clear.
Go to the top of the page
 
+
bis2k
post Jan 6 2010, 02:20 PM
Post #6

UtterAccess Guru
Posts: 506



Thanks I will give both suggestions a try.
Go to the top of the page
 
+
doctor9
post Jan 6 2010, 03:51 PM
Post #7

UtterAccess VIP
Posts: 9,430
From: Wisconsin



For what it's worth, Ace's linked article is a Ferrari compared to my Flintstones-mobile. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/smile.gif)

Dennis
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 04:06 AM