试试:
Private Sub Command6_Click() On Error Resume Next Dim qdf As QueryDef d = CurrentProject.Path & "\comm" With Application.FileSearch .LookIn = d .FileType = msoFileTypeDatabases .Execute For i = 1 To .FoundFiles.Count DoCmd.TransferDatabase acImport, "Microsoft Access", .FoundFiles(i), acTable, "SaleLibA", "SaleLibA" Next i For i = 1 To CurrentDb.TableDefs.Count If InStr(1, CurrentDb.TableDefs(i).Name, "SaleLibA") > 0 Then s = s & "select * from " & CurrentDb.TableDefs(i).Name & " union all " End If Next i End With
SQL = Left(s, Len(s) - 10) Set qdf = CurrentDb.CreateQueryDef("me", SQL)
End Sub
|