473,397 Members | 2,028 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,397 software developers and data experts.

auto increment if newdata ???

hi all !
I have a text field with contruction: 0001-COM.
I need to it automatically increase 0002-COM when add new record and
.....
Any help with appreciated.
Luan

Dec 27 '06 #1
6 3766
lu********@yahoo.com wrote:
hi all !
I have a text field with contruction: 0001-COM.
I need to it automatically increase 0002-COM when add new record and
....
Any help with appreciated.
Luan
If the text suffix is always going to be "-COM" then there is no reason to store
this and good reasons NOT to. If you just use formatting of a number field
(format = "0000-COM") then it is trivial to get the maximum numeric value
already in use and add 1 to it for new records. I would use the Form's
BeforeUpdate event...

If Me.NewRecord Then
Me!ID = Nz(DMax("ID", "TableName"), 0) + 1
End If

Assuming the ID field is indexed the above will be very efficient. To do the
same with a Text field containing the "-COM" on the end will be more complicated
and inefficient since an index cannot be used.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Dec 27 '06 #2
thanks a lot, Rick.
It is great.
Luan
Rick Brandt wrote:
lu********@yahoo.com wrote:
hi all !
I have a text field with contruction: 0001-COM.
I need to it automatically increase 0002-COM when add new record and
....
Any help with appreciated.
Luan

If the text suffix is always going to be "-COM" then there is no reason to store
this and good reasons NOT to. If you just use formatting of a number field
(format = "0000-COM") then it is trivial to get the maximum numeric value
already in use and add 1 to it for new records. I would use the Form's
BeforeUpdate event...

If Me.NewRecord Then
Me!ID = Nz(DMax("ID", "TableName"), 0) + 1
End If

Assuming the ID field is indexed the above will be very efficient. To do the
same with a Text field containing the "-COM" on the end will be more complicated
and inefficient since an index cannot be used.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Dec 27 '06 #3
hi Rick & all !
Maybe i need your help revising my code.
i create my invoice number as code below.
It nearly work as my mine.

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim DB As Database
Dim RS As Recordset
Dim Str As String
Dim i As Integer

Set DB = CurrentDb
Set RS = DB.OpenRecordset("TCHITIETHANGXUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Date), "00") & Right(Year(Date), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv", "tchitiethangxuat"), 4) + 1
Me.INV = Format(i.Text, "0000") & Str ------i want cover i to text but not
succeed, i want to store i with 4 characters---
Else
Me.INV = "0001" & Str
End If
End Sub

how can i do this ??
Any ideas will be appreciated.
thansk in advance
Luan from VietNam

Dec 27 '06 #4
sorry Rick & all !
I found my stupid mistake.:)
just release ---.text----
Thanks all.
Dec 27 '06 #5
Start by revising your storage... store the sequential number, as a numeric
integer or long integer, separately from the text portion of your invoice
number... format and concatenate them when you need to display or use them.
That will simplify incrementing the sequential number...

In the future, it would be helpful if you would tell us _what_ you are
trying to do, instead of giving code that "almost works" for us to either
determine, or guess, what you are trying to do from the "how you thought it
would work and it almost did".

Trying to have "coded" identification, as your invoice number, was
convenient in manual systems, but rarely necessary in automated systems. A
number which uniquely identifies the entity works nicely, and information
such as date, category, etc., are easily retrievable. If it is necessary to
satisfy the managment, or users, with "coded" identification, it is much
easier to form the coded identification when needed to be displayed to the
humans to whome it may be meaningful, rather than storing it in humanly
convenient form in a medium (rotating memory on a computer) that a human
can't even see.

Larry Linson
Microsoft Access MVP

"luanhoxung" <lu********@yahoo.comwrote in message
news:4f******************************@localhost.ta lkaboutdatabases.com...
hi Rick & all !
Maybe i need your help revising my code.
i create my invoice number as code below.
It nearly work as my mine.

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim DB As Database
Dim RS As Recordset
Dim Str As String
Dim i As Integer

Set DB = CurrentDb
Set RS = DB.OpenRecordset("TCHITIETHANGXUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Date), "00") & Right(Year(Date), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv", "tchitiethangxuat"), 4) + 1
Me.INV = Format(i.Text, "0000") & Str ------i want cover i to text but not
succeed, i want to store i with 4 characters---
Else
Me.INV = "0001" & Str
End If
End Sub

how can i do this ??
Any ideas will be appreciated.
thansk in advance
Luan from VietNam

Dec 27 '06 #6
Hi Larry !

You & others here are kind and knowledge.
I got a lot abt knowledge and behaviour from here.
I remember ur advise to post my question in later :)
Thanks.
Luan
Larry Linson wrote:
Start by revising your storage... store the sequential number, as a numeric
integer or long integer, separately from the text portion of your invoice
number... format and concatenate them when you need to display or use them.
That will simplify incrementing the sequential number...

In the future, it would be helpful if you would tell us _what_ you are
trying to do, instead of giving code that "almost works" for us to either
determine, or guess, what you are trying to do from the "how you thought it
would work and it almost did".

Trying to have "coded" identification, as your invoice number, was
convenient in manual systems, but rarely necessary in automated systems. A
number which uniquely identifies the entity works nicely, and information
such as date, category, etc., are easily retrievable. If it is necessary to
satisfy the managment, or users, with "coded" identification, it is much
easier to form the coded identification when needed to be displayed to the
humans to whome it may be meaningful, rather than storing it in humanly
convenient form in a medium (rotating memory on a computer) that a human
can't even see.

Larry Linson
Microsoft Access MVP

"luanhoxung" <lu********@yahoo.comwrote in message
news:4f******************************@localhost.ta lkaboutdatabases.com...
hi Rick & all !
Maybe i need your help revising my code.
i create my invoice number as code below.
It nearly work as my mine.

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim DB As Database
Dim RS As Recordset
Dim Str As String
Dim i As Integer

Set DB = CurrentDb
Set RS = DB.OpenRecordset("TCHITIETHANGXUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Date), "00") & Right(Year(Date), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv", "tchitiethangxuat"), 4) + 1
Me.INV = Format(i.Text, "0000") & Str ------i want cover i to text but not
succeed, i want to store i with 4 characters---
Else
Me.INV = "0001" & Str
End If
End Sub

how can i do this ??
Any ideas will be appreciated.
thansk in advance
Luan from VietNam
Dec 27 '06 #7

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

Similar topics

2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Paulovič Michal | last post by:
hi all, I have problem with SERIAL field type (or sequence functionality). I have table with three columns - ID, IDS, NAME. I want auto-increment IDS grouped by ID. Example: 1, 1, Ferdo 1, 2,...
5
by: vul | last post by:
In VB6 there is Auto Increment check box in Project Properties, which allow you have a new version every time you compile the project. Is there any easy way to have this feature in VB 2005? Some...
2
by: john | last post by:
Is it true that if I split my access database in backend and frontend and I implement custom auto increment for the ID fields, that my database is ready to be used in a multi-user environment? I...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
5
by: David Wright | last post by:
Hello Everyone I would be grateful if someone could help me with the automatic increment of a field on my subform called ‘Test_SrNo’. I am Using Microsoft Office 2000. The auto entry of the...
13
by: BobLewiston | last post by:
Using Visual C# 2008 Express and SQL Server 2008 Express, I would like to insert new records into database "AdventureWorks", table "Person.Contact". To my surprise, this table's int-value identity...
3
by: paulyXvpf | last post by:
Hello, all... Just finished a handy tutorial that has helped me understand how to auto increment and post to a web page... but its only a Web User Control passing values from VB.NET method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.