2
私はこの機能を使って、数字8000から始まる数字と毎日8000に戻る数字を自動的に配列しようとします。また、この関数はギャップがないことを保証しようとします。したがって、手動入力があり、数字がギャップを作成する場合、フィールドは手動入力からシーケンスされません。しかし、私は前のエントリから同じ番号にとどまるだけで、コードが機能するようには見えず、増加しません。DMax番号シーケンス修正ギャップ
Public Function fRetNextInSequence() As Long
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Dim rstClone As DAO.Recordset
'If there are no Records in tblData, then have the Function return 8000
If DCount("strSerialNumber", "tblOrderData", "dtmDateOrdered=#" & Date & "#") = 0 Then
fRetNextInSequence = 8000
Exit Function
End If
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("tblOrderData", dbOpenSnapshot)
Set rstClone = rst.Clone
rst.MoveLast 'Move to Last Record [MyNum]
With rstClone 'Move to Next-to-Last Record [MyNum]
.MoveLast
.Move -1 'Clone now at Next-to-Last Record [MyNum]
End With
With rst
Do While Not rstClone.BOF
If Abs(![strSerialNumber] - rstClone![strSerialNumber]) > 1 Then
fRetNextInSequence = (rstClone![strSerialNumber] + 1) 'Found the Gap!
Exit Function
End If
.MovePrevious 'Move in sync, 1 Record apart
rstClone.MovePrevious
Loop
End With
rst.MoveLast
fRetNextInSequence = (rst![strSerialNumber] + 1) 'No Gap found, return next number in sequence!
rstClone.Close
rst.Close
Set rstClone = Nothing
Set rst = Nothing
End Function
If SOS = "ES-S" Then
SerialNbrValue = fRetNextInSequence
'SerialNbrValue = Val(Nz(DMax("strSerialNumber", "tblOrderData", "dtmDateOrdered=#" & Date & "#"), 7999)) + 1
Else
SerialNbrValue = ""
End If
プロシージャ外のコードを表示しないのはなぜに?その 'もしSOS ...ならば、コンパイルエラーが起こるはずです。 – June7