473,806 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create unique serial number based on todays date in format MMDDYY-XXX in VB?

9 New Member
I need to identify parts we buy at our plant. I want to give each a unique serial number that is based on the date. We may have multiple parts on a given date so I want to have the unique serial number in the format:
MMDDYY-XXX where XXX is a unique number that start with 001 for the first item of the day. 002 for the second, etc. but starting over the next day.

When a user enters info in the database, it may already have a number. If not, I want them to push a button and it takes today's date, serializes it based on the number of parts already existing for that date, and place that unique serial number in the PartID box for them. Then they can proceed to enter the other info.

I am learning Access 2007 and have been doing some Macros but at this point I tend to find things others have done and then learn them enough to modify them. I can figure this out eventually but I don't use Access enough to be efficient and I don't have the time.

Ideally, a VB macro done for me...at least enough to query the existing data and create the number would be great.

Does anyone already have somethign like this or can someone get me started???

Thanks!
Dec 17 '10
13 8117
Scott Kaempfe
9 New Member
Hello. I just got back from vacation and proofed my code and everything seems to be working fine. Thank you.

Now I have a follow-up question. It turns out that some of our old unique serial numbers have a letter in front of the number which represents our vendor.

When I add these numbers to the table, the code to find how many unique serial numbers start with the date crashes.

It says:
"Run-time error '3464':
Data type mismatch in criteria expression"

and it shows that it stops at the line:
intCount = DCount("*", "ToolingID" , "Left$([SerialNo],6) = " & Format$(Date, "mmddyy"))



Full code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command17_Click()
  2. Dim intCount As Integer
  3. Dim rst As DAO.Recordset
  4. Dim strSQL As String
  5. Dim fGenerateSerialNumber As String
  6. Dim Counttest
  7.  
  8.  
  9. 'Are there any Serial Numbers for today's Date?
  10. intCount = DCount("*", "ToolingID", "Left$([SerialNo],6) = " & Format$(Date, "mmddyy"))
  11. MsgBox intCount
  12.  
  13. 'Create a Recordset based on all Records having a Serial Number consisting of Today's Date.
  14. 'Order By the Numeric Component (XXX in mmddyy-XXX) Descending so greatest Value is the 1st
  15. 'Record in the Recordset
  16. strSQL = "SELECT [SerialNo] FROM ToolingID WHERE Left$([SerialNo],6) = '" & Format$(Date, "mmddyy") & "'" & _
  17.          " ORDER BY Val(Right$([SerialNo],3)) DESC;"
  18.  
  19. If intCount > 0 Then        'Yes there is at least 1, so Increment the Last
  20.   Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  21.   fGenerateSerialNumber = Left$(rst![SerialNo], 7) & Format$(Val(Right$(rst![SerialNo], 3) + 1), "000")
  22. Else                        'No Serial Number for Today's Date, so set it
  23.   fGenerateSerialNumber = Format$(Date, "mmddyy") & "-001"
  24. End If
  25. MsgBox fGenerateSerialNumber
  26. Me.inFormat = fGenerateSerialNumber
  27. Me.ToolingID = fGenerateSerialNumber
  28.  
  29. 'Clean Up, if required
  30. If Not rst Is Nothing Then
  31.   rst.Close
  32.   Set rst = Nothing
  33. End If
  34. End Sub
Jan 6 '11 #11
ADezii
8,834 Recognized Expert Expert
Can you strip this Vendor Code from the Serial Number if it is present via an Update Query?
Jan 7 '11 #12
Scott Kaempfe
9 New Member
I guess so. But since the code I have is counting the number of times that the first 6 digits of the serial number matches the 6 numbers of teh date in the MMDDYY format, would that mean I need to do an update query that strips the vendor code off of EVERY serial number?

I'm open to it...just not sure how to go about it.

Why am I getting that error? Will it give me the error if the alpha vendor code is at the END of the unique number? I can probably manipulate my codes to do that.
Jan 7 '11 #13
Scott Kaempfe
9 New Member
Actually, I just confirmed that if the letter is not in the first 6 digits, it works fine. I will just need to make sure that there are no letters in the first 6 digits.

Is there an easy way to make sure that when an operator enters a unique number that it gives them an error message if the code has a letter in the first 6 digits???

I can make a note on the form but want to mistake proof it.
Jan 7 '11 #14

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

Similar topics

1
2420
by: weiwei | last post by:
hi, is there anyway that I can validate my date format in asp?? I have tried like date=now(), that gives me like 5/14/2004, the format should be mmddyy, no space, no dash, and has to include 0 if month is from 1-9, for example 01, 02, like that???? please help me out thanks in advance Wei
1
3366
by: Paul | last post by:
Hi Guys, I have written an application in Visual C#, I wish to add serial number validation dll to the installer, how do I go about doing this. Thanks in advance. Paul Mathebula
6
5248
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 anything complicated just a way to generate a 16 character number. Is there an easy way to do this...? Thanks
1
2661
by: Beckster6701 | last post by:
I have a MSAccess database that is linked to a SQL server. I cannot change the SQL server datatype as I am not the only one that uses the database. I'm trying to convert the text field to a valid date or number format so that the field will report correctly. Currently the text field is appears as follows: Test Date: YYYYMMDD (i.e. 20061206) I have used a CDate format, but am getting a type mismatch error when I attempt to run the...
5
6922
by: Jassim Rahma | last post by:
my CPU mac address is BFEBFBFF000006F6 and my software name is : shefa is there any function or encryption way in C# to generate a 24 digits (alpha numeric) from both CPu MAC address and software name?
16
18275
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 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...
2
12679
by: sheperson | last post by:
Hi, I have been working for several months on a sofware and now it is finished. I have a problem now and it is this: Because I live in a country which there is no copyright law in it (Iran!!!!). As soon as I give the software to some customers, the software will be copied illegally and I don't want this happen. Now I wonder if anyone could help me on how to create a lock or a serial number for the software. I want my software to...
4
3059
by: naaniibabu | last post by:
I have one number i want to convert in to a date format the size of the value is =8 Char 20091212 i ant to conver it in to a date format my sysyem doent understand wether its adate or not its taking as a number Thanks Nani
1
2107
by: Keshia | last post by:
I have a database that is for keeping track of inventory. I need to have my form for entering new inventory to automatically make a new serial number based on the category of the new item. The serial numbers are currnently like this: AA###### "AA" = Category code "######" = the next number I currently have a category combobox and an item combobox and the serial number txt field. The options in the item combobox change based on the...
0
9597
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,...
0
10618
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10371
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
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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
4329
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
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.