将SQL结果值放在下拉列表vba访问中

时间:2016-09-06 08:35:41

标签: sql vba access

我想在Access下拉列表中放置一个值,但我不能......这是我的代码:

Dim rst As DAO.Recordset
Dim SQL1 As String
Dim resultat As String

SQL1 = "SELECT Table_de_correspondance_Galiléi.Num_EB FROM Table_de_correspondance_Galiléi WHERE Table_de_correspondance_Galiléi.Code_projet = " & "'" & CodeProjet1.Value & "'"
Set rst = CurrentDb.OpenRecordset(SQL1, dbOpenForwardOnly, dbReadOnly)
resultat = rst(0)
Me.NumEB1.Value = resultat

rst.Close

" NumEB1"是我的下拉列表

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个;

> Dim SQL1 As String
> 
> 
> SQL1 = "SELECT Table_de_correspondance_Galiléi.Num_EB FROM
> Table_de_correspondance_Galiléi WHERE
> Table_de_correspondance_Galiléi.Code_projet = " & "'" &
> CodeProjet1.Value & "'"
> 
> Me.NumEB1.RecordSource = SQL1