문제

I'm planning to make a simple helpdesk form. One of the attributes it needs is a unique number.

How can I create a unique identifier, starting with a string? Example: KL0001 and KL0002

It must be a number which is unique.

도움이 되었습니까?

해결책

You could use a standard AutoNumber field to store the numerical portion, and then a separate Calculated column that formats the result prefixing "KL" and padding the AutoNumber field with the necessary zeros.

Example:

SELECT "KL" & Fmt(autonum_field, "0000") AS unique_identifier
FROM YourTable;

다른 팁

The problem with using an autonumber is, among other things, if someone starts to enter the record the autonumber is assigned. Then, if the user cancels adding the record the autonumber value is lost. So you are better to wait until the user finishes entering the record and in the forms AfterInsert event run the code as per the following KB article.

ACC2000: How to Create a Multiuser Custom Counter

That said I'd still use an autonumber field in the table so that it's easier to work with child tables.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top