我有一个带有表[tblManipulate]的Access数据库,其中四个字段填充了数据:
[tblManipulate].[Name]
[tblManipulate].[Description]
[tblManipulate].[Price]
[tblManipulate].[Account code]
我还有一个名为[tblDescLookup]的150条描述表,需要像查找表一样使用它来操作帐户代码。示例条目如下:
[tblDescLookup].[Description Lookup] [tblDescLookup].[Account Code Result]
*demonstration* 10000
*coding* 12000
*e-mail* 13000
在[tblManipulate]中获取每个记录并检查[tblManculate]。[描述]字段对[tblDescLookup]的最佳方法是什么。[描述查找],如果'喜欢',将帐户代码结果分配到原始表中'找到匹配?
在我看来,这就像Access不是这项工作的最佳工具之一,但这是我被指示使用的。我将不胜感激任何帮助或见解(或替代方案!)。谢谢!
答案 0 :(得分:1)
这样的事情应该适合你。
Dim Description As String
Dim lookupDescription As String
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(SELECT * FROM tblManipulate)
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'good habit
Do Until rs.EOF = True
Description = rs("Description")
Dim rsLookUp As DAO.Recordset
Set rsLookUp = CurrentDb.OpenRecordset(SELECT * FROM tblDescLookup)
If Not (rsLookUp .EOF And rsLookUp .BOF) Then
rsLookUp .MoveFirst 'good habit
Do Until rsLookUp.EOF = True
lookupDescription = rsLookUp("Description Lookup")
If() Then 'match criteria
'assign value
End if
rsLookUp.MoveNext
Loop
Else
MsgBox "No records in the recordset."
End If
rs.MoveNext
Loop
Else
MsgBox "No records in the recordset."
End If
答案 1 :(得分:0)
Oy公司。你这里需要一个循环。我会在记录集中打开tblDescLookup:
Set rec = CurrentDB.OpenRecordset ("Select * from tblDescLookup")
然后循环遍历每条记录并以这种方式运行查询:
Do While rec.EOF = False
Set rec2 = CurrentDB.OpenRecordset ("Select * from rec where Description like '" & rec("Description Lookup") & "'")
rec.MoveNext
Loop
或许你需要改为使用Update语句?我不能把它写在我的头顶,但你明白了。
答案 2 :(得分:0)
你尝试过这样的事吗?
Update tblManipulate as t1
Set [Account Code] = (Select [Account Code Result] from [tblDescLookup] where [Description Lookup] = t1.[Description])