473,498 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find the last number of a record

NV
I've a table called GReg with the fields GNumber, ControlNumber,
ArticleCode, ProdNumber and Date.

In a form I select the ArticleCode from one combo box, and I define the
number of records to create.

Then for each record to be created I need to find the last
ControlNumber used within the selected GNumber (one GNumber may
correspond to several ArticleCode), and increment it by one. Is this
possible ?

Thank you all in advance

Nuno

Jan 10 '06 #1
3 1970
Because you say that one GNumber may correspond to several Article Code (and
for other reasons), it sounds like you should have more than one table, but
without knowing anything about the real-world situation to which your
database applies it is difficult to tell. Especially puzzling is your
saying you define the number of records to create.
Having said that, here is a sample database with a way of automatically
incrementing a number:
http://www.rogersaccesslibrary.com/d...berProblem.mdb

"NV" <nu*********@potain.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I've a table called GReg with the fields GNumber, ControlNumber,
ArticleCode, ProdNumber and Date.

In a form I select the ArticleCode from one combo box, and I define the
number of records to create.

Then for each record to be created I need to find the last
ControlNumber used within the selected GNumber (one GNumber may
correspond to several ArticleCode), and increment it by one. Is this
possible ?

Thank you all in advance

Nuno

Jan 10 '06 #2
NV
This is the code I'm using :

strSQL = _
"INSERT INTO RegistoGamas(NumeroGama, NumeroControlo,
CodigoArtigo) " & _
"VALUES('" & Me.NumeroGama & "', #, '" & Me.CodigoArtigo & "')"
lngLastUsedID = Nz(DMax("[NumeroControlo]", "[RegistoGamas]",
"[NumeroGama]=" &_ [txtNumeroGama]), 0)
Set db = CurrentDb
For lngID = (lngLastUsedID + 1) To (lngLastUsedID + lngAddCount)

db.Execute Replace(strSQL, "#", Str(lngID)), dbFailOnError
Next lngID

and it works fine if I use always the same ArticleCode, if I chose
other ArticleCode it will change the ControlNumber of previous records
and will mess it all up

I've looked and looked again but I can't guess what's wrong with this
code

Jan 10 '06 #3
You asked if it is possible to increment by one. I suggested a solution (by
means of the link). Now I learn that you already had code, but it is not
working. Had you mentioned the code in the first place I would not have
responded, as I do not quite understand what you are doing.
Anybody attempting to respond is probably unfamiliar with your database, so
may not know what to make of your remarks about ArticleCode and
ControlNumber. If these are CodigoArtigo and NumeroControlo, it would be
best to just say so and not leave it to potential responders to translate.
I recall that there were a few details in your original post, which brings
me to another point, which is that you should include the text of previous
messages in you reply so that it is not necessary to flip back and forth
between messages.

"NV" <nu*********@potain.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
This is the code I'm using :

strSQL = _
"INSERT INTO RegistoGamas(NumeroGama, NumeroControlo,
CodigoArtigo) " & _
"VALUES('" & Me.NumeroGama & "', #, '" & Me.CodigoArtigo & "')"
lngLastUsedID = Nz(DMax("[NumeroControlo]", "[RegistoGamas]",
"[NumeroGama]=" &_ [txtNumeroGama]), 0)
Set db = CurrentDb
For lngID = (lngLastUsedID + 1) To (lngLastUsedID + lngAddCount)

db.Execute Replace(strSQL, "#", Str(lngID)), dbFailOnError
Next lngID

and it works fine if I use always the same ArticleCode, if I chose
other ArticleCode it will change the ControlNumber of previous records
and will mess it all up

I've looked and looked again but I can't guess what's wrong with this
code

Jan 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4868
by: Ann | last post by:
Hello everyone, hope someone can help me with this. I have a SQL stored procedure that inserts a record into a table, creates a cursor to fetch the last record that was added to get the unique...
8
2556
by: JIMMIE WHITAKER | last post by:
Can someone help on this: I am just learning, and I'm connecting to the the northwindcs.mdf tables / open file is northwindcs.adp. This is the sample installed using msde, which is supposed to be...
2
2057
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to...
2
8812
by: PC | last post by:
Hi, I have used the DLast("!","")function to find and display the last entry in a table. How would I go about displaying the last record in a table that is not Null? Thanks in advance ...pc
8
2096
by: Richard Sherratt | last post by:
It's a database keeping info about people and is expected to contain 20,000 to 25,000 people. I could put a GoToPerson Combo on the form, but the customer and I are not to keen on that. It makes...
8
5465
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
9
5037
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
1
1727
by: lorirobn | last post by:
Hi, I have a report that has a query as its record source. The query picks up records from a table that meet certain criterion. The report then counts how many records there are for each key...
5
2484
by: Digitallad | last post by:
I have a table with Coloms : CardID : Timein : Bookstaken : Timeout : Booksback When a person comes in his card_id number is filled in to the field "cardid" Time in = "now()" Bookstaken is...
0
7125
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
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
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
7203
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...
1
6885
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...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.