从Access中的另一个表获取输入

时间:2013-06-27 14:21:19

标签: sql ms-access-2007 access-vba ms-access-2010

我有一张名为Employee_id的表。我想循环表数据,并为表数据的每一行运行一些其他查询,其中输入将是employee_id行的值。

是否可以在Access中编写类似的内容?

1 个答案:

答案 0 :(得分:1)

Dim rsEmployees As DAO.Recordset
Dim stringName As String
Dim strSQL As String
Dim strSQL1 As String

strSQL = "SELECT Employee_Name..., etc FROM Employee_id "

Set rsEmployees = CurrentDb.OpenRecordset(strSQL)
rsEmployees.MoveFirst

Do While Not rsEmployees.EOF

stringName = rsEmployees!Employee_Name

strSQL1 = "What ever your query is"

Do.Cmd.RunSQL (strSQL)
rsEmployes.MoveNext

Loop 

End Sub

设置1:创建一个选择Employee_ID表中每条记录的查询

Set 2:While循环遍历上述Query的记录集

设置3:使用rsEmployess!ColumnName访问每个记录字段

设置4:在查询中使用上述字符串