如何在VB中以MMDDYY-XXX格式创建基于今天日期的唯一序列号? [英] How to create unique serial number based on todays date in format MMDDYY-XXX in VB?

查看:145
本文介绍了如何在VB中以MMDDYY-XXX格式创建基于今天日期的唯一序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要识别我们在工厂购买的零件。我想给每个人一个基于日期的唯一序列号。我们可能在给定日期有多个部分,所以我希望以下列格式获得唯一的序列号:

MMDDYY-XXX其中XXX是一个唯一的编号,以当天第一项的001开头。 002,等等,但是从第二天开始。


当用户在数据库中输入信息时,它可能已经有一个数字。如果没有,我希望他们按下按钮,它需要今天的日期,根据该日期已存在的部件数量将其序列化,并将该唯一的序列号放在PartID框中。然后他们可以继续输入其他信息。


我正在学习Access 2007并且已经做了一些宏但是在这一点上我倾向于找到别人已经完成的事情然后再学习它们修改它们。我最终可以解决这个问题,但我没有使用Access足够高效,而且我没有时间。


理想情况下,VB宏为我做了.. 。至少足以查询现有数据并创建数字会很棒。


有没有人有这样的事情,或者有人能让我开始吗?


谢谢!

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!

推荐答案

现在订阅...


你总是在评估当前日期,还是你从其他地方读取日期值?
Just subscribing for now...

Are you always evaluating against the Current Date, or are you reading a Date Value from elsewhere?


嗯......我在表单上设置的方式是表单字段有日期。我目前通过制作今天的日期来设定日期。所以我有一个宏从这个字段中获取日期,所以如果它是今天或其他日期真的不重要。


如果出于某种原因这很重要,我会选择今天的日期。


示例:

1. John有一个新工具需要一个唯一的ID号

2.它查询数据库以确定在同一天是否有任何工具登录数据库

3.返回MMDDYY-XXX中最高的唯一编号

4.为今天的日期和下一个序列号分配一个新的序列号。
Well..the way I had it set up on the form was that the form field had the date. I am currently setting the date by making it TODAY''s date. So I have a macro getting the date from this field so it really shouldn''t matter if it is TODAY or another date.

If for some reason it matters, I would go with TODAY''s date.

Example:
1. John has a new tool that needs a unique ID number
2. It queries the database to determine if there are any tools logged into the database on this same date
3. Returns the highest unique number in MMDDYY-XXX
4. Assigns a new serial number with todays date and the next serial number.


OK - let我先说这是一个正在进行的工作,所以忽略它的格式化等等


这是我的代码。代码粗体是我遇到问题的地方。我需要创建一个只提取具有今天日期的序列号的查询,或者它只查找以今天日期开始的最后一个唯一序列号。不确定最好的方法。


Private Sub Command0_Click()

Dim strCurrentYear As String

Dim strCurrentDay As String

Dim strCurrentDate As String

Dim strStaticValue As String

Dim strSequentialNo As String

Dim strLastSerialNo As String

Dim strLastSequentialNo As String

Dim strNextSequentialNo As String

Dim fGenerateNextSerialNumber As String

Dim strCurrentDateTest As String


strCurrentDate =格式
OK - let me preface this by saying that this is a work in progress so ignore how it is formatted etc

Here is my code. The code is bold is where I am having problems. I need to either create a query that only extracts Serial Numbers with todays date OR it just looks for the last unique serial number that starts with Todays date. Not sure of the best approach.

Private Sub Command0_Click()
Dim strCurrentYear As String
Dim strCurrentDay As String
Dim strCurrentDate As String
Dim strStaticValue As String
Dim strSequentialNo As String
Dim strLastSerialNo As String
Dim strLastSequentialNo As String
Dim strNextSequentialNo As String
Dim fGenerateNextSerialNumber As String
Dim strCurrentDateTest As String

strCurrentDate = Format


这篇关于如何在VB中以MMDDYY-XXX格式创建基于今天日期的唯一序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆