查询变量中的结果

时间:2013-04-24 17:37:10

标签: sql vba ms-access access-vba

这就是我想要做的。单击btnDraw后,我希望Access运行查询测试并将结果带回字符串获胜者。然后在lblWinner中显示结果。

Private Sub btnDraw_Click()

Dim winner As String

winner = ???????

lblWinner.Caption = winner

End Sub

这是TEST查询的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);

谢谢!

1 个答案:

答案 0 :(得分: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)
 ")

为了便于阅读,我添加了一些换行符。您可能想要删除它们。我也对你的Order By条款感到好奇。这不是你问题的一部分,但是如何通过随机数排序让你获胜?