自动生成号码 [英] Automatically generate numbers

查看:325
本文介绍了自动生成号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动生成一个跟踪号码。

I am in need of a tracking number that automatically generates.

我说这在行动插入之前(见下文),但我9号之后有问题。

I added this in the 'Before Insert' action (see below), but I am having a problem after the number 9.

我![追踪#] = NZ(DMAX([跟踪#],[TblTrackingNum]),0)+ 0.01

Me![Tracking#] = Nz(DMax("[Tracking#]", "[TblTrackingNum]"), 0) + 0.01

我的追踪号码总是启动与89669.这code工作,直到达到十号。

My tracking number always starts of with 89669. This code works until it reaches the number ten.

追踪号码应该这样做: 89669.1 ... 89669.2 ... 89669.3 ... 89669.4 ... 89669.5 .....

The tracking number should do this: 89669.1... 89669.2... 89669.3... 89669.4... 89669.5.....

但9之后的数字变成89670.我需要它说89669.10。

But after 9 it changes the number to 89670. I need it to say 89669.10.

有什么建议?

推荐答案

首先,追踪号码必须是一个字符串,如已经在评论中提到约翰尼骨头。
所以,最后一个字段必须是一个字符串,但实际越来越多的需要是数字型的(为了适当增加它)的。

First of all, the tracking number needs to be a string, as already mentioned by Johnny Bones in the comments.
So the final field needs to be a string, but the actual increasing number needs to be a numeric type (in order to properly increase it).

将自动递增字段到表中的(并使其成为主键)的。照片 这将成为您的追踪号码的越来越重要的作用。

Put an auto-increment field into the table (and make it the primary key).
That will become the increasing part of your tracking number.

那么,有不同的方式如何产生的追踪号码指出,自增字段:

Then, there are different ways how to generate your tracking number out of that auto-increment field:

1)创建在MS Access,其选择从该表并生成跟踪号码的查询。

1) Create a query in MS Access that selects from the table and generates the tracking number.

SELECT "89669." & [ID] AS TrackingNumber, YourTable.*
FROM YourTable

不要直接使用表,总是 SELECT 从查询:

SELECT * FROM qryYourTable WHERE ...

2)创建一个名为 TrackingNumber 表中的一个附加文本字段。
每次在表中插入新行,打电话从code,填补该领域具有正确值的查询:

2) Create an additional text field called TrackingNumber in the table.
Each time you insert a new row in the table, call a query from your code that fills the field with the correct value:

Public Function FillTrackingNumbers()

    CurrentDb.Execute "UPDATE YourTable SET TrackingNumber = '89669.' & [ID] WHERE TrackingNumber Is Null"

End Function

这篇关于自动生成号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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