2013-04-24 86 views
1

這是我正在嘗試做的事情。一旦點擊了btnDraw,我希望Access運行查詢測試並將結果帶回字符串贏家。然後在lblWinner中顯示結果。在一個變量中查詢結果

Private Sub btnDraw_Click() 

Dim winner As String 

winner = ??????? 

lblWinner.Caption = winner 

End Sub 

這是測試查詢的SQL代碼:

SELECT TOP 1 [Goth Table].representative 
FROM [Goth Table] 
WHERE ((([Goth Table].[Would you like to be entered in the drawing])=Yes)) 
ORDER BY Rnd(Int(Now()*id)-Now()*id); 

謝謝!

回答

0

嘗試:

Winner= 
currentdb.openrecordset(" 
SELECT TOP 1 [Goth Table].representative 
FROM [Goth Table] 
WHERE [Goth Table].[Would you like to be entered in the drawing]=Yes 
ORDER BY Rnd(Int(Now()*id)-Now()*id);").fields(0) 
") 

我加入增加了可讀性,一些換行。你可能想要刪除這些。我也很好奇你的訂單條款。這不是你問題的一部分,但是如何用隨機數字排序讓你成爲贏家?

+0

這就是我選擇隨機記錄的方式。然後使用該記錄的代表在lblWinner中顯示 – 2013-04-24 17:50:33

+0

有沒有更好的方法建議? – 2013-04-24 19:28:44

+0

我試圖對你的迴應進行投票,但我不能,除非我有15個聲望! – 2013-04-25 13:44:33