在MS上生成数字。访问 [英] Generate Number on MS. Access

查看:67
本文介绍了在MS上生成数字。访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你好,

我想在MS上生成一个唯一的ID字段。访问。该ID为

,包含10位数字,包含来自26个字母的5个字母的组合

和5个数字,从1到9.字母和数字被选中

随机。当我在表单上单击带有VB代码的按钮时,它将在表格调用客户表上创建ID。有人可以帮我吗

如何编写VB代码来生成ID?


先谢谢你的帮助!!
< br>


Hello,
I am looking to generate a unique ID field on MS. Access. The ID is
with 10 digits with the combination of 5 Letters from the 26 letters
and 5 Numbers from 1 to 9. The letters and numbers are picked
randomly. When I click a button with the VB code on a form, it will
create the ID on a table call "Customer table". Can someone help me on
how to write the VB code to generate the ID??

Thanks in advance for your help!!

推荐答案

2006年7月26日14:15:31 -0700,兰花 < yh ****** @ yahoo.comwrote:


这个领域的目的是什么?为什么不使用自动编号?


-Tom。

On 26 Jul 2006 14:15:31 -0700, "Orchid" <yh******@yahoo.comwrote:

What is the purpose of this field? Why not use an AutoNumber?

-Tom.


>
你好,<我希望在MS上生成一个唯一的ID字段。访问。该ID为10位数字,包含26个字母的5个字母和1个到9个的5个字母。字母和数字随机选取。当我在表单上单击带有VB代码的按钮时,它将在表调用Customer表上创建ID。有人可以帮我吗
如何编写VB代码来生成ID?

在此先感谢您的帮助!!
>
Hello,
I am looking to generate a unique ID field on MS. Access. The ID is
with 10 digits with the combination of 5 Letters from the 26 letters
and 5 Numbers from 1 to 9. The letters and numbers are picked
randomly. When I click a button with the VB code on a form, it will
create the ID on a table call "Customer table". Can someone help me on
how to write the VB code to generate the ID??

Thanks in advance for your help!!


试试这个。它应该工作

子测试()

Dim str As String

Dim num As Double

Dim uniqueKey As字符串

''以下将创建一个密钥,然后你必须测试是否是

唯一的


GenerateNumber:

num = Int(Rnd * 100000)

str =" yourstringhere"

uniqueKey = num& str $ / $
MsgBox uniqueKey

''这将测试它是否是唯一的

Dim rs As Recordset

设置rs = CurrentDb.OpenRecordset(" table1")

rs.MoveFirst

请勿做rs.EOF

如果rs!fieldwithkey = uniqueKey然后GoTo GenerateNumber

rs.MoveNext

循环

结束子

Try this. It should work
Sub testing()
Dim str As String
Dim num As Double
Dim uniqueKey As String
''the following will create a key, then you must test to see if is
unique

GenerateNumber:
num = Int(Rnd * 100000)
str = "yourstringhere"
uniqueKey = num & str
MsgBox uniqueKey
'' this will test to see if it is unique
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("table1")
rs.MoveFirst
Do While Not rs.EOF
If rs!fieldwithkey = uniqueKey Then GoTo GenerateNumber
rs.MoveNext
Loop
End Sub


非常感谢您的回复!

我创建了一个名为Table1的表,但仍然出现错误:运行时

错误 13'':类型不匹配。我还需要做什么?

有没有办法从26个ABC字母中随机选择5个字母?我试过了
但是没有工作。

非常感谢你的帮助!


T先生写道:
Thanks so much for your reply!
I created a table called "Table1", but still had an error: "Run-time
error''13'': Type Mismatch". What else do I need to do?
Is there a way to randomly select 5 letters from the 26 ABC letters? I
tried but didn''t work.
Your help is greatly appreciated!

Mr. T wrote:

试试这个。它应该工作


子测试()

Dim str As String

Dim num As Double

Dim uniqueKey As String

''以下将创建一个键,然后你必须测试是否是

unique


GenerateNumber:

num = Int(Rnd * 100000)

str =" yourstringhere"

uniqueKey = num& str $ / $
MsgBox uniqueKey

''这将测试它是否是唯一的

Dim rs As Recordset

设置rs = CurrentDb.OpenRecordset(" table1")

rs.MoveFirst

请勿做rs.EOF

如果rs!fieldwithkey = uniqueKey然后GoTo GenerateNumber

rs.MoveNext

Loop

End Sub
Try this. It should work
Sub testing()
Dim str As String
Dim num As Double
Dim uniqueKey As String
''the following will create a key, then you must test to see if is
unique

GenerateNumber:
num = Int(Rnd * 100000)
str = "yourstringhere"
uniqueKey = num & str
MsgBox uniqueKey
'' this will test to see if it is unique
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("table1")
rs.MoveFirst
Do While Not rs.EOF
If rs!fieldwithkey = uniqueKey Then GoTo GenerateNumber
rs.MoveNext
Loop
End Sub


这篇关于在MS上生成数字。访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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