Using Access 2003, I need to create an automatic Serial Number.
Example "7235-E001"
"7" is current year
"235" is day
"-E" is static
"001" is sequencial, restarting at "001" each day
I set a table field with "=right(Format(Now(),"yy") & Format(Format(Now(),"y"),"000"),4)" to create the year/day number.----I should be able to add &"-E"& to add the static "-E"----I tried to add this all together with the "autonumber", but that obviously failed since the autonumber will not reset each day. Also, I lost the placeholders on the sequencial number "001".
I have little to no knowledge of VB, and if possilbe, would like to keep all expressions regulated to queries and tables and forms. If not possible, I will see what I can understand.
Please keep in mind, I am a complete noob, so speak to me like I am an idiot. Thank you.
16 18181
Using Access 2003, I need to create an automatic Serial Number.
Example "7235-E001"
"7" is current year
"235" is day
"-E" is static
"001" is sequencial, restarting at "001" each day
I set a table field with "=right(Format(Now(),"yy") & Format(Format(Now(),"y"),"000"),4)" to create the year/day number.----I should be able to add &"-E"& to add the static "-E"----I tried to add this all together with the "autonumber", but that obviously failed since the autonumber will not reset each day. Also, I lost the placeholders on the sequencial number "001".
I have little to no knowledge of VB, and if possilbe, would like to keep all expressions regulated to queries and tables and forms. If not possible, I will see what I can understand.
Please keep in mind, I am a complete noob, so speak to me like I am an idiot. Thank you.
I could only spend a very short time on this, but this Function should properly generate the next Serial Number per your specifications. There are only a couple of simple assumptions:- Your Table Name is tblTest, make the appropriate substitution if necessary.
- The [SerialNo] Field within this Table is called [SerialNo].
- The Day component you refer to in the Serial Number is a Julian Date (number of Days from the first of the year).
- Any questions, feel free to ask.
- Public Function fGenerateNextSerialNumber()
-
Dim strCurrentYear As String
-
Dim strCurrentDay As String
-
Dim strStaticValue As String
-
Dim strSequentialNo As String
-
Dim strLastSerialNo As String
-
Dim strLastSequentialNo As String
-
Dim strNextSequentialNo As String
-
-
strCurrentYear = Right(Year(Now()), 1)
-
strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), Now()) + 1
-
strStaticValue = "-E"
-
-
'get ready to extract the Sequential Number
-
strLastSerialNo = DLast("[SerialNo]", "tblTest") 'produces 7235-E001
-
strLastSequentialNo = Right(strLastSerialNo, 3) 'produces 001
-
-
'Generate the Next Sequential Number
-
strNextSequentialNo = Format(Val(strLastSequentialNo) + 1, "000") 'produces "002"
-
-
'Generate the next, Unique, Serial #
-
fGenerateNextSerialNumber = strCurrentYear & strCurrentDay & strStaticValue & strNextSequentialNo
-
End Function
This is kind of what I was afraid of. I have no idea where I would put the VB in the database.
This is kind of what I was afraid of. I have no idea where I would put the VB in the database.
Place =fGenerateNextSerialNumber() in the Default Value Property of the [ Serial Number] Field. Anytime you add a New Record, the results of this Function will be placed in this Field.
Roger, I will have access to the database tomorrow morning, I will try at that time, thank you. I'll reply back whether I manage or not.
Roger, I will have access to the database tomorrow morning, I will try at that time, thank you. I'll reply back whether I manage or not.
Just make sure to substitute your Table name for tblTest and your Field Name for SerialNo or else the code will not work.
To see if I could get this to work, I created a new table. I named the
table "tblTest. I entered 3 fields. Field 1 - ID (autonumber), Field 2
-
SerialNo (no format), Field 3 - data (no format).
I then went to the VB (Tools/Macro/Visual Basic Editor). I entered the
code as typed. When I opened the VB, it had autopopulated "option
compare database" on the top line, so I left that information in, and
placed the new code below it.
When I added =fGenerateNextSerialNumber into the default data for the
"SerialNo" field, the =fGenerateNextSerialNumber changed to read
="fGenerateNextSerialNumber".
I then changed the table to "datasheet view" and added data to the
"data" field, but the "SerialNo" field populated with
"fGenerateNextSerialNumber".
I went back to VB and deleted "option compare database", but the
"SerialNo" field still populates with "fGenerateNextSerialNumber" when
I add data to the "data" field.
Am I putting the code in the right place, or should I have formated the
"SerialNo" field somehow?
Hopefully I explained well enough.
Thank you.
- In Form Design View.
- Right Click on the [SerialNo] Field.
- Select Properties.
- Select the Data Tab.
- In Default Value, enter =fGenerateNextSerialNumber()
My apologies for not getting back to you in a timely manner, things have been hectic. I made the corrections that you pointed out. Now the database is giving me an error on the
strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), , Now()) + 1
line. When opening the serial number table, I receive "Compile error: Arguement not optional: warning, and it highlights the above mentioned script line.
My apologies for not getting back to you in a timely manner, things have been hectic. I made the corrections that you pointed out. Now the database is giving me an error on the
strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), , Now()) + 1
line. When opening the serial number table, I receive "Compile error: Arguement not optional: warning, and it highlights the above mentioned script line.
It seems as though you inadvertantly added another comma, thus the Error. The correct syntax is: - strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), Now()) + 1
Roger, I will fix the error when I get backto the office on Monday. Thank you.
Roger, I will fix the error when I get backto the office on Monday. Thank you.
You are quite welcome.
Sorry about taking so long to respond.
Thank you for your assistance, and the scripting!
Dear ADezii,
When I enter =fGenerateNextSerialNumber(), in default value field property of tblTest.SerialNo and save, I receive notification stating "unknown function '=fGenerateNextSerialNumber()'". Further more I have added the code in class module of VB window. Can you please help on this issue?
@HAMIZ
Make sure that the Function in in a Standard Code Module and not a Form's Module.
Yes, It is in Standard Code Module.
it works fine in "LOCALS" VB window and gives correct result.
Along with my last statement, It also gives error for strLastSerialNo stating "Run Time error '94' Invalid use of NULL" if there is no any record in the said table, i.e. we have write 1st value in [SerialNo] manually.
Hello,
I would like to generate a unique Serial number for each record set.
The Format is:
Year-String-Counter ----- Format = YYYY-PPAP-0000
Where the table Name = tbl_Detail_PPAP
the field = SequenceNumber
This is my code:
Public Function fGenerateNextSerialNumber()
Dim SequenceNumber As String
Dim strCurrentYear As String
Dim strStaticValue As String
Dim strSequentialNo As String
Dim strLastSerialNo As String
Dim strLastSequentialNo As String
Dim strNextSequentialNo As String
strCurrentYear = Right(Year(Now()), 4)
strStaticValue = "-PPAP"
'get ready to extract the Sequential Number
'If SequenceNumber = 0 Then
strLastSerialNo = DLast("[SequenceNumber]", "tbl_Detail_PPAP") 'produces 2016-PPAP-0001
strLastSequentialNo = Right(strLastSerialNo, 4) 'produces 0001
'Generate the Next Sequential Number
strNextSequentialNo = Format(Val(strLastSequentialNo) + 1, "0000") 'produces "0002"
'Generate the next, Unique, Serial #
fGenerateNextSerialNumber = strCurrentYear & strStaticValue & strNextSequentialNo
DoCmd.RunCommand acCmdSaveRecord
'End If
End Function
I have followed the exact procedures as suggested above. The code is in the Standard module. When I run the code, I get the following error "Invalid use of Null (Error 94)" on the code line: strLastSerialNo = DLast("[SequenceNumber]", "tbl_Detail_PPAP")
Please help me..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tony Clarke |
last post by:
Hi,
I'm trying to write a system thats used for about 50 clients that uses html
forms and php to log details. The problem is that when a client loads the
form page it's given a value which is...
|
by: Nitin |
last post by:
Hello,
We are trying to figure out how to get a unique identifier for a machine.
Our application is a C# windows application that talks to our server via a
webservice. Every time our webservice...
|
by: UJ |
last post by:
Is there any number I can get that is truly unique for a computer that can't
be changed? I want to have a system whereby I have a computer that accesses
a web service based on some unique value...
|
by: expect |
last post by:
Hello,
Trying to get this MySql create table command to work, no luck.
create sequence serial;
CREATE TABLE outbound (
source char(100) default '',
destination char(100) default '',
sport...
|
by: Yavuz Bogazci |
last post by:
Hi, we are developing an winforms application for task management. We want
generate a serial number wich includes Username, Company Name and another
Information as String. How can i create from...
|
by: BRINER Cedric |
last post by:
Synopsis
CREATE { TEMPORARY | TEMP } ] TABLE /table_name/ (
{ /column_name/ /data_type/ ]
| /table_constraint/ }
)
) ]
...
...
|
by: JJ |
last post by:
Now I know this question has been asked many times, but I cannot seem to
find a good site which summarises the methods possible in vb .net.
I am after a way of producing a unique serial number...
|
by: Arne Beruldsen |
last post by:
I have a windows app using vb.net 2005.
I would like to create a serial number based on a couple of characteristics
of the customers computer (computer name, HD number..etc). I don't need...
|
by: Paul Bromley |
last post by:
Ok - I have given up on trying to find the active IP address for a given PC.
For licensing purposes I need to retrive a unique identifier from the PC
that the program is installed on. The Hard disk...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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: 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...
| |