Sorry for spelling
Below current code
Code:
DoCmd.DeleteObject acTable, "PPA300RAP" ‘ Rmove table with final result
DoCmd.SetWarnings False
DoCmd.OpenQuery "CtempPPA300" ‘ run query which creating table base on order number
DoCmd.SetWarnings True
'''''''''''''''''''''''''''''''''''''''''''''''
Dim rs As DAO.Recordset 'create DAO recordset to load sequence values
Dim lngOne As Long, lngTwo As Long
Set rs = CurrentDb.OpenRecordset("SELECT PPA300RAP.tbNumer FROM PPA300RAP") 'populate rs
If Not (rs.BOF And rs.EOF) Then 'if TRUE there are no records so just exit IF block
rs.MoveFirst
lngOne = Right(rs.Fields("tbNumer"), 4) 'get last 4 characters from 1st record
With CurrentDb
.Execute "DELETE * FROM PPA300INRAP", dbFailOnError 'flush tblSequence2
.Execute "INSERT INTO PPA300INRAP (tbNumer2) VALUES ('" & rs.Fields("tbNumer") & "')", dbFailOnError 'add 1st complete sequence value
End With
rs.MoveNext 'move to next record...
Do While Not rs.EOF 'quit when end of recordset file is reached
lngTwo = Right(rs.Fields("tbNumer"), 4) '...and get 4 characters of next sequence value. Leading zeros are ignored
'subtract value 1 from value 2. If diff > 1, write complete sequence value to table
If (lngTwo - lngOne) > 1 Then
rs.MovePrevious
CurrentDb.Execute "INSERT INTO PPA300INRAP (tbNumer2) VALUES ('" & rs.Fields("tbNumer") & "')", dbFailOnError
rs.MoveNext
CurrentDb.Execute "INSERT INTO PPA300INRAP (tbNumer2) VALUES ('" & rs.Fields("tbNumer") & "')", dbFailOnError
End If
lngOne = lngTwo 'now set value 1 = value 2 so as to compare to next value after 2
rs.MoveNext 'move to next record to get next value
Loop
rs.MoveLast
rs.MovePrevious
CurrentDb.Execute "INSERT INTO PPA300INRAP (tbTekst2) VALUES ('" & rs.Fields("tbTekst") & "')", dbFailOnError
End If
End Sub