473,411 Members | 1,991 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,411 software developers and data experts.

Create Specific Unique Serial Number II

ADezii,

I am also trying to create a similar auto number, minus the E. I have entered the code above (removing all instances of strStaticValue = "-E") and have entered =fGenerateNextSerialNumber() as the default value. I don't get any errors when I compile the code but in my access form I get "#Error". Do you have any ideas? Here is what I have in my code (sorry it's not as neat as yours above):
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function fGenerateNextSerialNumber()
  5. Dim strCurrentYear As String
  6. Dim strCurrentDay As String
  7. Dim strStaticValue As String
  8. Dim strSequentialNo As String
  9. Dim strLastSerialNo As String
  10. Dim strLastSequentialNo As String
  11. Dim strNextSequentialNo As String
  12.  
  13. strCurrentYear = Right(Year(Now()), 1)
  14. strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), Now()) + 1
  15. 'strStaticValue = "-E"
  16.  
  17. 'get ready to extract the Sequential Number
  18. strLastSerialNo = DLast("[RA_Number]", "Maintenance_Authorization")        'produces 7235-E001
  19. strLastSequentialNo = Right(strLastSerialNo, 3)         'produces 001
  20.  
  21. 'Generate the Next Sequential Number
  22. strNextSequentialNo = Format(Val(strLastSequentialNo) + 1, "000")   'produces "002"
  23.  
  24.   'Generate the next, Unique, Serial #
  25.   'fGenerateNextSerialNumber = strCurrentYear & strCurrentDay & strStaticValue & strNextSequentialNo
  26.   fGenerateNextSerialNumber = strCurrentYear & strCurrentDay & strNextSequentialNo
  27. End Function
Sep 18 '07 #1
8 1931
ADezii
8,834 Expert 8TB
ADezii,

I am also trying to create a similar auto number, minus the E. I have entered the code above (removing all instances of strStaticValue = "-E") and have entered =fGenerateNextSerialNumber() as the default value. I don't get any errors when I compile the code but in my access form I get "#Error". Do you have any ideas? Here is what I have in my code (sorry it's not as neat as yours above):

Option Compare Database
Option Explicit

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("[RA_Number]", "Maintenance_Authorization") '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
fGenerateNextSerialNumber = strCurrentYear & strCurrentDay & strNextSequentialNo
End Function
I'll have a look and get back to you.
Sep 18 '07 #2
Thank you for your time!
Sep 18 '07 #3
ADezii
8,834 Expert 8TB
Thank you for your time!
Not a problem. The code seems fine, but let us test it and be sure. This will make it easier to isolate the problem. Place these 3 lines of code anywhere and execute them - you should get a valid response. Let me know how you make out.
Expand|Select|Wrap|Line Numbers
  1. Dim strResponse As String
  2.  
  3. strResponse = fGenerateNextSerialNumber()
  4. MsgBox strResponse       'should get the return value of the Function
Sep 19 '07 #4
NeoPa
32,556 Expert Mod 16PB
gymgyrl4,

You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours. Another is that it will tend to mean that your new question is not seen as such, and may get overlooked by many of our experts (You appreciate that they're not looking for answered questions). Please post your questions in their own threads in future (See How to Ask a Question).

MODERATOR.
Sep 19 '07 #5
Sorry bout it...didn't mean to be a hijaker!

ADezii,

I added the msgbox code and I get the error:
Run-time error '94':
Invalid use of Null

and it points to the line of code:
strLastSerialNo = DLast("[RA_Number]", "Maintenance_Authorization")

The RA_Number field in the Maintenance_Authorization table is of data type number (long integer) and is not required.
Sep 19 '07 #6
NeoPa
32,556 Expert Mod 16PB
Don't worry about the thread hijack. It's sorted now and I'm sure you won't do it again now you know.
When a field has not got the "Required" setting set to yes, this means that it is possible for some records in the table to have that field missing. When it is missing it returns a Null value. To get around this you can use the Nz() function.
Expand|Select|Wrap|Line Numbers
  1. strLastSerialNo = Nz(DLast("[RA_Number]", "Maintenance_Authorization"), 0)
Do you mean to return the number and then assign it to a string variable by the way?
Sep 19 '07 #7
Don't worry about the thread hijack. It's sorted now and I'm sure you won't do it again now you know.
When a field has not got the "Required" setting set to yes, this means that it is possible for some records in the table to have that field missing. When it is missing it returns a Null value. To get around this you can use the Nz() function.
Expand|Select|Wrap|Line Numbers
  1. strLastSerialNo = Nz(DLast("[RA_Number]", "Maintenance_Authorization"), 0)
Do you mean to return the number and then assign it to a string variable by the way?
Nope, just return the value. That works perfectly! Thanks!
Quick question...It returned 7262001. Tomorrow will the last three digit count restart, giving me 7263001?
Sep 19 '07 #8
NeoPa
32,556 Expert Mod 16PB
No problem.
I don't know off the top of my head as I'm not sure exactly what code you're using. Post me up the code (Don't forget the CODE tags) and I'll check that out for you if I can.
Sep 19 '07 #9

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

Similar topics

7
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...
4
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...
18
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...
6
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...
16
by: malteselemon | last post by:
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...
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...
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
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
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
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...

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.