lundi 11 septembre 2017

How to randomize number from ms access database column only in vb6?

Please help me randomize the numbers from the ms access only. I need to random only the numbers in the ID column from tblParticipants. Because error/s occurs when an instance of deletion of record or change of record from the database.

Sub winsave()
'con.Execute "delete from tblParticipants where ID='" & lblID.Caption & "' "
con.Execute "insert into tblRaffleWin values('" & lblID.Caption & "','" & lblName.Caption & "','" & lblOrga.Caption & "','" & Date & " - " & Time & " ')"
End Sub

Private Sub tmrDraw_Timer()
Dim A As Integer
Dim arrData() As String
Dim sData As String
Dim i As Integer
Dim rs As New ADODB.Recordset
Dim rsRaffle As New ADODB.Recordset
rs.Open "select * from tblParticipants a where not exists (select ID from tblRaffleWin b where a.ID=b.ID) ", con, adOpenStatic
'rs.Open "SELECT TOP 1 ID FROM tblParticipants ORDER BY rnd(ID)", con, adOpenStatic
If Not rs.EOF Then
Randomize
lblID.Caption = Int(Rnd * rs.RecordCount)
rsRaffle.Open "Select * from tblParticipants where ID='" & lblID.Caption & "' ", con, adOpenDynamic
lblName.Caption = rsRaffle!Name
lblOrga.Visible = False
End If
cmdDraw.Enabled = False
tmrPick.Enabled = True
End Sub

Private Sub tmrPick_Timer()
Dim rsCheck As New ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim rsWin As New ADODB.Recordset
tmrDraw.Enabled = False
lblName.Visible = True
lblOrga.Visible = True
'rs.Open "select * from tblParticipants a where not exists (select ID from tblRaffleWin b where a.ID=b.ID) ", con, adOpenDynamic
rs.Open "SELECT TOP 1 ID FROM tblParticipants ORDER BY rnd(ID)", con, adOpenStatic
If Not rs.EOF Then
lblID.Caption = Int(Rnd * rs.RecordCount)
rsWin.Open "Select * from tblParticipants where ID='" & lblID.Caption & "' ", con, adOpenDynamic
lblName.Caption = rsWin!Name
lblOrga.Caption = IIf(IsNull(rs!Organization), "", rs!Organization)
winsave
cmdDraw.Enabled = True
tmrDraw.Enabled = False
tmrPick.Enabled = False
cmdDraw.SetFocus
Form_Load
End If
End Sub




Aucun commentaire:

Enregistrer un commentaire