Henrik Larsson <si***@home.se> wrote in message news:<41**********************@news.newsgroups.ws> ...
Thanks,
The scrips works like a charm, although it seems to be very heavy on the
CPU. When I run the query access takes 70-80% CPU time for 3-4 minutes
om my 2,8GHz P4 before it's finished with the query and can display it.
I'm running on quite a small data, only a few thousand records. Is this
normal? If not, what could be causing it?
BR
Henrik Larsson
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Try this behind a command button on a form:
Dim MyDB As Database
Dim IDRS As Recordset
Dim FanRS As Recordset
Dim NewRS As Recordset
Dim strSQL As String
Dim lngI As Long
Dim lngIDCount As Long
Dim lngJ As Long
Dim lngFanCount As Long
Dim strID As String
Dim tdf As TableDef
Dim fld As Field
Dim boolFanOutFound As Boolean
Set MyDB = CurrentDb
boolFanOutFound = False
For Each tdf In MyDB.TableDefs
If tdf.Name = "tblFanOut" Then
boolFanOutFound = True
Exit For
End If
Next tdf
If Not boolFanOutFound Then
Set tdf = MyDB.CreateTableDef("tblFanOut")
' Create new Field object.
Set fld = tdf.CreateField("ID", dbLong)
tdf.Fields.Append fld
Set fld = tdf.CreateField("IP1", dbText, 50)
tdf.Fields.Append fld
Set fld = tdf.CreateField("IP2", dbText, 50)
tdf.Fields.Append fld
Set fld = tdf.CreateField("IP3", dbText, 50)
tdf.Fields.Append fld
Set fld = tdf.CreateField("IP4", dbText, 50)
tdf.Fields.Append fld
Set fld = tdf.CreateField("IP5", dbText, 50)
tdf.Fields.Append fld
tdf.Fields.Refresh
MyDB.TableDefs.Append tdf
MyDB.TableDefs.Refresh
Else
strSQL = "DELETE tblFanOut FROM tblFanOut;"
MyDB.Execute strSQL
End If
strSQL = "SELECT DISTINCT ID FROM tblIPs;"
Set IDRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
strSQL = "tblFanOut"
Set NewRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
If IDRS.RecordCount > 0 Then
IDRS.MoveLast
lngIDCount = IDRS.RecordCount
IDRS.MoveFirst
For lngI = 1 To lngIDCount
strID = IDRS("ID")
strSQL = "SELECT ID, IP FROM tblIPs WHERE ID = " & strID & ";"
Set FanRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
If FanRS.RecordCount <> 0 Then
FanRS.MoveLast
lngFanCount = FanRS.RecordCount
If lngFanCount > 5 Then lngFanCount = 5
FanRS.MoveFirst
NewRS.AddNew
NewRS("ID") = FanRS("ID")
For lngJ = 1 To lngFanCount
NewRS("IP" & lngJ) = FanRS("IP")
If lngJ <> lngFanCount Then FanRS.MoveNext
Next lngJ
NewRS.Update
End If
FanRS.Close
Set FanRS = Nothing
If lngI <> lngIDCount Then IDRS.MoveNext
Next lngI
End If
IDRS.Close
Set IDRS = Nothing
Set MyDB = Nothing
MsgBox ("Done.")
James A. Fortune