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
8 1931
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.
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. - Dim strResponse As String
-
-
strResponse = fGenerateNextSerialNumber()
-
MsgBox strResponse 'should get the return value of the Function
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.
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.
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. - 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?
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. - 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?
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.
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: 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: 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: 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: 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...
|
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: 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: 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...
|
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: 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...
|
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: 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...
|
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...
| |