0

如果有人可以帮助我,我将非常感激。我已经完成了 95% 的项目,但我被困在最后一项任务中。

基本上,我有一个函数可以搜索我的 Access 数据库中的所有表并在列表框中返回找到的值。一切正常,除非我在一个表中有相同的字符串,然后我的 dlookup 返回它获得的第一个值。但是在某些表中,该值仅记录一次,并且该功能当然可以正常工作。我试图根据 Recordset.absoluteposition 获取 DLookup,但我现在失败了好几天,没有任何解决方案。我通过这个项目搜索了我的方式,我不是专家。谁能帮帮我?:/这是我的代码:

Public Function fSearchForString(strSearchString) As Boolean
On Error GoTo Err_fSearchForString
 
Dim tdfa As dao.TableDef
Dim MyDBs As dao.Database
Dim MyRS As Recordset
Dim intNumOfFields As Integer
Dim intCounter As Integer
 
Set MyDBs = CurrentDb
 
DoCmd.Hourglass True
  
For Each tdfa In CurrentDb.TableDefs
  If Not tdfa.Name Like "MSys*" Or Not tdfa.Name Like "MSys*" Then    'ignore System Tables
    Set MyRS = MyDBs.OpenRecordset(tdfa.Name, dbOpenDynaset)
      intNumOfFields = MyRS.Fields.Count
        For intCounter = 0 To intNumOfFields - 1
          Do While Not MyRS.EOF
            If InStr(MyRS.Fields(intCounter).Value, strSearchString) > 0 Then

Dim stringergebnis As Variant
stringergebnis = MyRS.Fields(intCounter).Value
Dim rackpos As Variant
rackpos = tdfa.Name
Dim rackposition As Variant
rackposition = DLookup("Rack_Position", tdfa.Name, "[Auftragsnummer]= '" & stringergebnis & "'")
Dim rackmaterial As Variant
rackmaterial = DLookup("Material", tdfa.Name, "[Auftragsnummer]= '" & stringergebnis & "'")
Dim rackvon As Variant
rackvon = DLookup("absort_Zeit", tdfa.Name, "[Auftragsnummer]= '" & stringergebnis & "'")


Forms!Probe_suchen.Liste103.AddItem Item:="" & "'" & stringergebnis & "'" & ";" & "'" & rackpos & "'" & ";" & "'" & rackposition & "'" & ";" & "'" & rackmaterial & "'" & ";" & "'" & rackvon & "'" & ""

 
            End If
            MyRS.MoveNext
          Loop
          MyRS.MoveFirst
        Next
  End If
Next
 
DoCmd.Hourglass False
 
MyRS.Close
Set MyRS = Nothing
 
fSearchForString = True
 
Exit_fSearchForString:
  Exit Function
 
Err_fSearchForString:
  fSearchForString = False
  MsgBox Err.Description, vbExclamation, "Error in fSearchForString()"
  DoCmd.Hourglass False
  If Not MyRS Is Nothing Then
    MyRS.Close
    Set MyRS = Nothing
  End If
    Resume Exit_fSearchForString
End Function
4

0 回答 0