我有一个数据库,其中有一个表,其中充满了用于检查另一个数据库的条件和错误消息。
我想运行一个循环,以便根据第二个数据库中的所有表检查每个条件,并生成一个给出错误的报告。
这在ms access中可能吗?
例如,
查询临界值表
id query error
1 speed<25 and speed>56 speed above limit
2 dist<56 or dist >78 dist within limit
我有超过 400 个类似的不同变量的查询。
我运行查询的表是
记录表
id speed dist accce decele aaa bbb ccc
1 33 34 44 33 33 33 33
2 45 44 55 55 55 22 23
问候
ttk
这是更多示例代码。它说明了两种不同类型的记录集的使用。您可能想阅读VBA 陷阱:使用记录集 http://allenbrowne.com/ser-29.html作者:艾伦·布朗和Access 2002 和 Access 更高版本中的保留字列表 http://support.microsoft.com/kb/286335.
Dim rs As DAO.Recordset
Dim rs2 As ADODB.Recordset
Set rs = CurrentDb.OpenRecordset("querycrit")
Set rs2 = CreateObject("ADODB.Recordset")
rs2.ActiveConnection = CurrentProject.Connection
For Each tdf In CurrentDb.TableDefs
'EDIT: TableDefs includes Microsoft System tables and '
'these should never be tampered with. They all begin with Msys '
'so we can leave them out of the loop here. '
If Left(tdf.Name, 4) <> "msys" And tdf.Name <> "querycrit" Then
rs.MoveFirst
strSQL = "SELECT * From [" & tdf.Name & "] WHERE "
Do While Not rs.EOF
On Error Resume Next
Debug.Print tdf.Name
rs2.Open strSQL & " " & rs![query]
If Err.Number = 0 Then
On Error GoTo 0
If Not rs2.EOF Then
Debug.Print rs![Error]
Debug.Print rs2.GetString
End If
End If
Err.Clear
rs2.Close
rs.MoveNext
Loop
End If
Next
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)