473,790 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3790
lu********@yaho o.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********@yaho o.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_BeforeInse rt(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.OpenRecordse t("TCHITIETHANG XUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Da te), "00") & Right(Year(Date ), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv" , "tchitiethangxu at"), 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********@yah oo.comwrote in message
news:4f******** *************** *******@localho st.talkaboutdat abases.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_BeforeInse rt(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.OpenRecordse t("TCHITIETHANG XUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Da te), "00") & Right(Year(Date ), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv" , "tchitiethangxu at"), 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********@yah oo.comwrote in message
news:4f******** *************** *******@localho st.talkaboutdat abases.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_BeforeInse rt(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.OpenRecordse t("TCHITIETHANG XUAT", dbOpenSnapshot)
Str = "-" & Format(Month(Da te), "00") & Right(Year(Date ), 2) & "/VF"
Me.INV.Format = Str
If RS.RecordCount 0 Then
i = Left(DMax("inv" , "tchitiethangxu at"), 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
12717
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 telling me that "Number of query values and destination fields are not the same." If I add a value for the auto increment field to the SQL String the data is entered into the table with no problems but obviously the auto increment field now...
6
5074
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 do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
5
5156
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, John 2, 1, Martin 1, 3, Elvira
5
5120
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 of my blocks of code check and compare versions of EXE and DLLs located on the local workstation and the server. So it's very important for me to have an incremented number in case the project was rebuilt. It can be done manually, of course, but I...
2
5547
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 found a zillion messages about auto increment and read some of them but it's confusing. Can someone point me to a simple custom auto increment example that I can download? Thank you, john
13
4728
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 i type in the details. I have just moved over to mysql server with access as the front end. I have setup the sql tables with the customer number as autonumber. When i go into the form and add a new customer it does not generate the
0
4456
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 tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members'). I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member'...
5
8101
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 incremented number would help to reduce errors and make data entry simpler. The next record in the Test_SrNo field should not have any entry in it until the text insertion point enters the Test_SrNo field. Example: If the last test serial number...
13
37570
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 column "ContactID" does not appear to be auto-increment. I don't know how to confirm for sure that this is so. (I have installed SQL Server Management Studio, if that helps.) How can I confirm this, and how can I make ContactID auto-increment? ...
3
4611
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 statements... I really need the increment and post from a SQL Server 2000 database See Example: http://sql-paul.com/lesson27_VB/Default.aspx See Flowchart/Code Behind (I created it in Visio) http://sql-paul.com/lesson27_VB/Control_State_Flowchart.htm
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
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 we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.