Помогите! В чём моя ошибка?
00002
00001
00003
Есть код, который читает его, прибавляет 1, и создаёт новую запись... Проблема: если поле ts_sub_id >= 00003, то 1 не прибавляется, я записывается 00003...
Вот код:
[COLOR=blue]
Public Sub WriteNewSubId(ts_id As String)
Dim FromSubTasks As DAO.Recordset
Dim NewId As String
Dim temp As String
Set FromSubTasks = Db.OpenRecordset("Select * from sub_tasks;")
NewId = Val(GetLastSubId(FromTasks.Fields("ts_subs_id"))) + 1
temp = Replace(FromTasks.Fields("ts_subs_id"), ";", ":")
FromSubTasks.MoveFirst
temp = Replace(ToHash(Val(FromSubTasks.Fields("ts_sub_id")) + Val("00001")), ":", "")
FromSubTasks.AddNew
FromSubTasks.Fields("ts_sub_id") = temp
FromSubTasks.Update
Set FromTasks = Nothing
Set FromSubTasks = Nothing
End Sub
Private Function ToHash(subId As String, Optional Key As Integer)
Dim iHash As Integer
iHash = 1
Dim temp As String
Do While iHash <= Len(subId)
temp = Mid(subId, iHash, 1)
If Len(temp) = 1 Then ToHash = ToHash & "0000" & Mid(subId, iHash, 1) & ":"
If Len(temp) = 2 Then ToHash = ToHash & "000" & Mid(subId, iHash, 1) & ":"
If Len(temp) = 3 Then ToHash = ToHash & "00" & Mid(subId, iHash, 1) & ":"
If Len(temp) = 4 Then ToHash = ToHash & "0" & Mid(subId, iHash, 1) & ":"
If Len(temp) = 5 Then ToHash = ToHash & "0" & Mid(subId, iHash, 1) & ":"
If Len(temp) = 6 Then ToHash = ToHash & Mid(subId, iHash, 1) & ":"
iHash = iHash + 1
Loop
End Function
[/COLOR]