Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Running REAL Slow

Status
Not open for further replies.

PSUIVERSON

Technical User
Nov 6, 2002
95
US
I am doing some simple formatting of data that I imported into fields and when it gets down to the dates section of the code it just RUNS and RUNS and RUNS. I have to do a CTRL Break because I can't figure it out. It shouldn't take so long...should it?

Sub formatTABLE()

Dim dbs As Database
Dim rst As Recordset

Dim i As Integer
Dim temp As Variant
Dim temp2 As Variant

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TEST", dbOpenDynaset)

rst.MoveFirst

' Format SS#
temp = Mid(rst!CSSNO, 4, 1)
If temp <> &quot;-&quot; Then
Do
temp = rst!CSSNO
temp2 = Left(temp, 3) + &quot;-&quot; + Mid(temp, 4, 2) + &quot;-&quot; + Right(temp, 6)
rst.Edit
rst!CSSNO = temp2
rst.Update
rst.MoveNext
Loop Until rst.EOF
End If

'Format IDCRATE

rst.MoveFirst

Do
temp = rst!CIDCRATE
If temp <> &quot;&quot; And temp > 100 Then
temp = FormatNumber(rst!CIDCRATE / 100, 2)
rst.Edit
rst!CIDCRATE = temp
rst.Update
End If
rst.MoveNext
Loop Until rst.EOF

'Format STARTBAL

rst.MoveFirst

Do
temp = Round((rst!startbal * -1), 2)

If temp <> 0 Then
rst.Edit
rst!startbal = temp
rst.Update
End If

rst.MoveNext

Loop Until rst.EOF

'Clean up the Dates

rst.MoveFirst

Do
temp = Left(rst!DATE3, 1)
If temp = &quot;.&quot; Then
i = Len(rst!DATE3)
temp = Right(rst!DATE3, i - 1)
rst.Edit
rst!DATE3 = temp
rst.Update
rst.MoveNext
End If
Loop Until rst.EOF

rst.MoveFirst

Do
temp = Left(rst!DATE2, 1)
If temp = &quot;.&quot; Then
i = Len(rst!DATE2)
temp = Right(rst!DATE2, i - 1)
rst.Edit
rst!DATE2 = temp
rst.Update
rst.MoveNext
End If
Loop Until rst.EOF

rst.MoveFirst

Do
temp = Left(rst!DATE1, 1)
If temp = &quot;.&quot; Then
i = Len(rst!DATE1)
temp = Right(rst!DATE1, i - 1)
rst.Edit
rst!DATE1 = temp
rst.Update
rst.MoveNext
End If
Loop Until rst.EOF

'Alert user they have finished

MsgBox (&quot;You have finished formatting the XYZ table&quot;)

dbs.Close

End Sub
 
Looking at this piece of code the movenext is inside an if statement. If the if does not get satisfied even ONE time it will loop forever.

Do
temp = Left(rst!DATE3, 1)
If temp = &quot;.&quot; Then
i = Len(rst!DATE3)
temp = Right(rst!DATE3, i - 1)
rst.Edit
rst!DATE3 = temp
rst.Update
rst.MoveNext
End If
Loop Until rst.EOF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top