472,373 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Problem using update query and Function ResetCounter()

Dear all,



I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !).


1) Given that I'm not a programmer I can't understand why numbering doesn't start always, running more times the update query, from the same starting parameter assigned (1000000000).
It seems to me that it takes memory last number calculated and running prox update it starts from last table row updated. I need to start always with 100000000 just to feed a 10 char field sequence reference. Is it possible to reset .... it to have this behavior each time I run the upt query ?



2) The update query has only 1 column of table with the update to set to:
GetNextCounter([NR_SEQUENZA])

The other colum is populated by : ResetCounter().

When you save and close it you loose the ResetCounter() column becouse no parameters are defined and so I can't run the query within a macro or from a button. That's a big problem becouse the query is within a weekly basis application and the end user can't go to edit the query and insert manually ResetCounter(). Is there a trick or a workaround ?? (I hope easy one...) to save and run the query each time with no edit it before ?



Any suggestion will be very appreciated.
Thanks in advance
Giovanni

==============
Option Explicit
Dim mlngCounter As Long

Function ResetCounter()
mlngCounter = 1000000000
End Function

Function GetNextCounter(pvar As Variant) As Long
mlngCounter = mlngCounter + 1
GetNextCounter = mlngCounter
End Function



In the Query:
Select [feilds...], ResetCounter(), GetNextCounter([a valid column]) From table....

How this works:
ResetCounter() takes no parameters so Access (being as efficient as ever:) only calls the function once before returning any rows as it thinks the return value will never change, hence the counter only gets reset once.
GetNextCounter() must be sent a valid column as a parameter, Access will realise that it must call this function for every row as each value sent can be different, so it increases the counter on each row.

Please note: This won't work very well for queries & forms where you intend to update data or scroll up and down as the calculated fields gets calculated again and the sequence number will keep going up and up.
Attached Images
File Type: jpg upd_query.jpg (16.1 KB, 290 views)
Dec 20 '09 #1
1 3028
ADezii
8,832 Expert 8TB
I am very confused as to the nature of your question, but it seems as though you are attempting to Increment a Counter at the same time that you are Resetting it. Assuming Table1 consists of a single Field named [NR_SEQUENZA], which contains a single Value to be used as a starting point to be incremented; you can change this Value (Reset), then Run your Query by executing the single line of code below:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE Table1 SET [NR_SEQUENZA] = 100000000;", dbFailOnError
Dec 21 '09 #2

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

Similar topics

7
by: Patrick Fisher | last post by:
Hi I have a table which Contains entries with RefCode field containing INVP or INVPD Common fields in each entry would be InvoiceNo, Total and PurTyp for example. You could have ...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
2
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: staticfire | last post by:
Hi i am in need of help with an ajax related problem on my site. I've coded an active users list which shows the members and guests online. I'm sure you've all seen active user lists before, like the...
2
by: panteraboy | last post by:
Hello again Humble helpfulls. Im having difficult with a module i have created. As its my first it was never going to be straightforward lol. But I was looking at one of the other treads and found it...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
2
coolv
by: coolv | last post by:
Hello I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me. Below is my code. thanks.............. <?php ...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.