I have the following code I have been running for several days and it worked perfectly. Today everytime I run it, it locks the database and says I no longer have exclusive use. And I can't save any changes to the code.
The only change I have made was add a timing loop to give the xml parser more time.
Bacically this code just imports an xml file and numbers each record set so I can pivot it into a new table.
Any insites would be appreciated.
Thanks
Simi
On Error GoTo Err_Command0_Click
Label1.Caption = "Removing Tables"
Me.Repaint
DoCmd.SetWarnings False
'clear the tables
DoCmd.DeleteObject acTable, "Field"
DoCmd.RunSQL "Delete * from Document"
DoCmd.RunSQL "Delete * from SourceFile"
'create new table from saved table so you reset the autonumber field
DoCmd.RunSQL ("SELECT * INTO Field FROM _Field WHERE 1 = 2")
DoCmd.SetWarnings True
Label1.Caption = "Importing XML"
Me.Repaint
'append data because we want to use the existing sturcture with recno and id
Application.ImportXML _
DataSource:="E:\_ctz\Administrator_57_ee12e277_VS216EO.xml", _
ImportOptions:=acAppendData
'ctz 6/10/2010
' DataSource:="E:\_ctz\Administrator_57_3db26ed7_VRZ160G.xml", _
'CTZ 5/10/2011
' DataSource:="E:\_ctz\Administrator_57_ee12e277_VS216EO.xml", _
'DoCmd.RunSQL ("ALTER TABLE Field ADD COLUMN Recno long")
'******************************************************************
' xml parser is not finishing and needs extra time.
'******************************************************************
Label1.Caption = "Closing XML Parser"
Me.Repaint
Dim PauseTime, Start
PauseTime = 5 ' Set duration in seconds
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
'******************************************************************
'******************************************************************
Label1.Caption = "Updating Records"
Me.Repaint
'set max rec locs about the record count
DAO.DBEngine.SetOption dbMaxLocksPerFile, 50000
Dim dbs As Database
Dim rst As Recordset
Dim Counter As Long
' set up a updateable recordset of your table
Set dbs = Nothing
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM field order by id", dbOpenDynaset)
Counter = 1
billnum = 0
' loop until run out of records
While Not rst.EOF
With rst
If rst.Fields(0).Name = "Name" And rst.Fields(0).Value = "Sys_DocName" Then
billnum = billnum + 1
End If
' sets your field to date for example
.Edit
![recno] = billnum
.Update
End With
'test
' moves to next record
rst.MoveNext
' one less record to go
Counter = Counter + 1
'Debug.Print Counter
'Let them know it is working update every 1000 records
If Counter Mod 1000 = 0 Then
Label1.Caption = Str(Counter) + " Completed!"
Me.Repaint
End If
' start loop again
Wend
Close #fnum
rst.Close
Set dbs = Nothing
Label1.Caption = "Import Finished"
Me.Repaint
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
The only change I have made was add a timing loop to give the xml parser more time.
Bacically this code just imports an xml file and numbers each record set so I can pivot it into a new table.
Any insites would be appreciated.
Thanks
Simi
On Error GoTo Err_Command0_Click
Label1.Caption = "Removing Tables"
Me.Repaint
DoCmd.SetWarnings False
'clear the tables
DoCmd.DeleteObject acTable, "Field"
DoCmd.RunSQL "Delete * from Document"
DoCmd.RunSQL "Delete * from SourceFile"
'create new table from saved table so you reset the autonumber field
DoCmd.RunSQL ("SELECT * INTO Field FROM _Field WHERE 1 = 2")
DoCmd.SetWarnings True
Label1.Caption = "Importing XML"
Me.Repaint
'append data because we want to use the existing sturcture with recno and id
Application.ImportXML _
DataSource:="E:\_ctz\Administrator_57_ee12e277_VS216EO.xml", _
ImportOptions:=acAppendData
'ctz 6/10/2010
' DataSource:="E:\_ctz\Administrator_57_3db26ed7_VRZ160G.xml", _
'CTZ 5/10/2011
' DataSource:="E:\_ctz\Administrator_57_ee12e277_VS216EO.xml", _
'DoCmd.RunSQL ("ALTER TABLE Field ADD COLUMN Recno long")
'******************************************************************
' xml parser is not finishing and needs extra time.
'******************************************************************
Label1.Caption = "Closing XML Parser"
Me.Repaint
Dim PauseTime, Start
PauseTime = 5 ' Set duration in seconds
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
'******************************************************************
'******************************************************************
Label1.Caption = "Updating Records"
Me.Repaint
'set max rec locs about the record count
DAO.DBEngine.SetOption dbMaxLocksPerFile, 50000
Dim dbs As Database
Dim rst As Recordset
Dim Counter As Long
' set up a updateable recordset of your table
Set dbs = Nothing
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM field order by id", dbOpenDynaset)
Counter = 1
billnum = 0
' loop until run out of records
While Not rst.EOF
With rst
If rst.Fields(0).Name = "Name" And rst.Fields(0).Value = "Sys_DocName" Then
billnum = billnum + 1
End If
' sets your field to date for example
.Edit
![recno] = billnum
.Update
End With
'test
' moves to next record
rst.MoveNext
' one less record to go
Counter = Counter + 1
'Debug.Print Counter
'Let them know it is working update every 1000 records
If Counter Mod 1000 = 0 Then
Label1.Caption = Str(Counter) + " Completed!"
Me.Repaint
End If
' start loop again
Wend
Close #fnum
rst.Close
Set dbs = Nothing
Label1.Caption = "Import Finished"
Me.Repaint
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click