以前做的
Private Sub cmdBegin_Click()
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
'If strFilePath = "" Then
' MsgBox "请先选择一个数据库文件! ", vbInformation + vbOKOnly, "提示信息"
' Exit Sub
'End If
If IntTotalPersonCount < 1 Then
MsgBox "目前注册用户为零不能进行抽奖! ", vbInformation + vbOKOnly, "提示信息"
Exit Sub
End If
If cmdBegin.Caption = "开始" Then
' Timer1.Enabled = True
cmdBegin.Caption = "停止"
cmdOK.Enabled = False
cmdCancel.Enabled = False
cmdBegin.SetFocus
End If
Dim j As Integer
Dim RstSQL As New ADODB.Recordset
Dim RndNumber As Integer
For j = 1 To 20 '如果一等奖1名 就是for j=1 to 1
flag = False
Randomize
RndNumber = Int(IntTotalPersonCount * Rnd + 1)
Rs.open "select count(*) as ll from temp1 WHERE Person_ID=" & RndNumber, CnnDSN, 1, 3
If Rs.Fields("ll") = 0 Then
'如果没有,则将抽取的人员插入到temp1表中
CnnDSN.Execute ("insert into temp1(Person_ID,Invoice_ID,Person_Name,Person_Tel,Checked,vl) SELECT Person_ID,Invoice_ID,Person_Name,Person_Tel,Checked,vl from Lottery_Table WHERE Person_ID=" & RndNumber)
Else
'保证每次必须抽取一个人
Do While flag = False
Randomize
RndNumber = Int(IntTotalPersonCount * Rnd + 1)
Rs.Close
Rs.open "select count(*) as ll from temp1 WHERE Person_ID=" & RndNumber, CnnDSN, 1, 3
If Rs.Fields("ll") = 0 Then
'如果没有,则将抽取的人员插入到temp1表中
CnnDSN.Execute ("insert into temp1(Person_ID,Invoice_ID,Person_Name,Person_Tel,Checked,vl) SELECT Person_ID,Invoice_ID,Person_Name,Person_Tel,Checked,vl from Lottery_Table WHERE Person_ID=" & RndNumber)
flag = True
End If
Loop
End If
Rs.Close
Next
cmdBegin.Caption = "开始"
Adodc1.CommandType = adCmdText
Adodc1.ConnectionString = CnnDSN
Adodc1.RecordSource = "SELECT Person_ID as 人员编号,Invoice_ID AS 身份证号,Person_Name as 姓名,Person_Tel as 电话 FROM temp1"