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

auto generate barcode number

given that in the table --books
field--barcode
type is string

the default value is "n288826830000"

I would like to make it autogenerate when I input new books via the form and not as a primary key

thus when I enter a book, the barcode should be
n288826830001, which has the ability +1 from the default value.

I have attempt to dmax the field in load as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim strmax As Long
  3. strmax = DMax("Barcode", "books") + 1
  4.  
  5. Me.Barcode.Value = strmax
  6.  
  7.  
  8. End Sub
I got runtime level error 6, with chinese error message that I don't even know what is it.

I know that it should be a number before I can strand the last digit and add one,
how about add one to the text, how could this be done ?
thanks.
Jan 6 '12 #1

✓ answered by Mariostg

Was not too sure what you meant by default value.

Anyway, here is something that should get you started I hope.
Expand|Select|Wrap|Line Numbers
  1. Function IncrementCode(code As String) As String
  2. Dim prefix As String 'n'
  3. Dim suffix As Double 'the digits'
  4.  
  5. prefix = Left(code, 1) 'n could be hard coded, but what if it changes...
  6. suffix = CDbl(Replace(code, prefix, "", 1, 1)) + 1
  7. IncrementCode = prefix & CStr(suffix)
  8. End Function
  9.  

7 2820
Rabbit
12,516 Expert Mod 8TB
How did you expect to add 1 to a string? Extract only the number portion, convert it, and then add one.
Jan 6 '12 #2
yes, that is what I want ;)
but another thing Is i want it to check the previous code
if it is up to n288826830001 the next one should be n288882683002
how is the syntax and which function to use ?
thanks,
Jan 6 '12 #3
i would like to ask how do you extract a string ?
convert and put it back ??
Jan 6 '12 #4
Mariostg
332 100+
There are many ways to achieve this. Does your initial string always follow the same pattern? I mean, one letter, followed by the digits?
Jan 6 '12 #5
yes.
Ineed, I thought I am stating the obvious
in table BOOKS
field barcode
the type is string
the default value is "n28888268300"

I would like to make it autogenerate barcode in my form when I
input new books and hit a button to save, clear then be ready for the next book input.

I am focusing on the former one, which is the ability to autogenerate barcode, which is "n2888826830001" and "n2888826830002" and so on.
the default string set is "n28888268300"
I know I can do it by dmax but as "n28888268300" is a text I have no idea how to turn plus one.
I tried to plus one with "1" but giving me 978xxxx01 values and later on run time error 6

thus would you mind suggesting me one way to
make this happen ?
my logic is
1.remove the default value from the table as this will be handled by code in the form
2. set string as follow ( pseudocode)
Expand|Select|Wrap|Line Numbers
  1. dim counter as integer
  2. str= "n28888268300" & counter +1
  3.  
  4.  
apparently this will not work and giving me wrong values because they are in different type i would like to either change it all to text and do the merging of string then save it to the record.

thanks.
Jan 6 '12 #6
Mariostg
332 100+
Was not too sure what you meant by default value.

Anyway, here is something that should get you started I hope.
Expand|Select|Wrap|Line Numbers
  1. Function IncrementCode(code As String) As String
  2. Dim prefix As String 'n'
  3. Dim suffix As Double 'the digits'
  4.  
  5. prefix = Left(code, 1) 'n could be hard coded, but what if it changes...
  6. suffix = CDbl(Replace(code, prefix, "", 1, 1)) + 1
  7. IncrementCode = prefix & CStr(suffix)
  8. End Function
  9.  
Jan 6 '12 #7
thanks dude, this exmaple gave me a hope to generate patron barcode and continue writing programme ;)

here is my code
Expand|Select|Wrap|Line Numbers
  1. Function IncrementCode(code As String) As String
  2. Dim prefix As String 'n'
  3. Dim suffix As Double 'the digits'
  4. '2888826830101 - 13 digits
  5.  
  6. prefix = Left(code, 12) 'n could be hard coded, but what if it changes...
  7. suffix = CDbl(Replace(code, prefix, "0", 1, 1)) + 1
  8. IncrementCode = prefix & CStr(suffix)
  9.  
  10. End Function
  11.  
  12. Public Sub add_catalog_Click()
  13.  
  14. Dim strmax As String
  15. Dim str As String
  16. Dim mycounter As String
  17. Dim count As Integer
  18.  
  19. Rem connection to db
  20.  
  21. Dim rsbooks As ADODB.Recordset
  22. Set rsbooks = New ADODB.Recordset
  23.  
  24.  
  25. Dim sqlbooks As String
  26. Dim sqltrans As String
  27. Dim strsql As String     ' for patrons
  28.  
  29. strsql = "Select * from books"
  30.  
  31. rsbooks.Open strsql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
  32. rsbooks.MoveLast
  33. MsgBox "the last barcode is " & rsbooks![Barcode]
  34.  
  35. str = rsbooks![Barcode]
  36.  
  37.  
  38.  
  39. Me.Barcode = IncrementCode(str)
  40. Exit Sub
  41.  
  42.  
  43. End Sub
  44.  



I have done what you have said and used a recordset to check the previous last used barcode , so it will add up everytime I press add :)


yeah hurray, I did it.
thanks Mariostg for your support and help.
Jan 6 '12 #8

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

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
6
by: Sebastien | last post by:
Hi, I am building a products database, linking sales and production. Each part has a unique sales Stock Code and Production Number. The sales stock code is a combination of letters and numbers...
2
by: SalimShahzad | last post by:
Dear Gurus, i had written following codes to auto generate the next claim no Private Const strC = "GCT/02/J/" Private Sub Command1_Click() Dim stra, stre As String Dim intb, intd As Integer...
2
by: angus | last post by:
Dear All, How to generate barcode label in asp.net? I am using MS SQL can reporting service in MS SQL do that? Thank you
2
by: G | last post by:
Hello Firends I want a sample code for developing an " auto genearte number " and want to store in database. Please if you find any code please send Thanks in Advance G
1
by: ganesh22 | last post by:
hi... I am doing a project asp.net with C#.my requirement I want to do auto generate password for my application that means when user forget his password when he clicks a link it will auto...
13
Hiren Joshi
by: Hiren Joshi | last post by:
Hi All, VB 6.0 and MS Access While Saving Record, I want Number to be Generated in following Format 140208-001, 140208-002, 140208-003 . . . etc... You must have noticed that 140208 is...
1
by: DanielLauJJ | last post by:
When inserting a record into a table, I want SQL Server to generate a number automatically for the Primary Key. (e.g. OrderID is 1, 2, 3 and so on) How to do it? (This behavior is similar to the...
0
by: ivyG | last post by:
How do you auto generate the name of the user who is logged in? For example, I had a Detail View to allow the user to insert the data, and i have a column named "Teacher In Charge 1". I wish...
2
by: Jagdish Patil | last post by:
I have project in asp.net with sql server backend. i want to auto generate a number for particular column. with the auto generated number i want to insert some other data in the same row same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.