Hi Vandat,
If I understand you correctly, you're looking for a way to get your next MAX sequence number (1 â 90) appended to the rest of your UID string. Hope thatâs in the ballpark.
If so, Iâd suggest first creating a table with a single field to store the current MAX value.
Table: tblMaxValue
-------------------
Field: MaxValue
DataType: Number
Default Value: 0
Then hereâs a function you can call to increment the MaxValue field, and return the new MaxValue.
Function GetNextMaxValue() As Integer
On Error GoTo ErrorHandler
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim intNextMaxValue As Integer
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "tblMaxValue", cnn, adOpenKeyset, adLockPessimistic
' increment current max value by 1
intNextMaxValue = rst("MaxValue") + 1
' validate new max value range
If intNextMaxValue <= 90 Then
rst("MaxValue") = intNextMaxValue
Else
rst("MaxValue") = 0
End If
rst.Update
' return new max value
GetNextMaxValue = rst("MaxValue")
' Clean up
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Function
ErrorHandler:
If Not rst Is Nothing Then
If rst.State = adStateOpen Then rst.Close
End If
Set rst = Nothing
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
End If
Set cnn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Function
I then placed a command button and a textbox on a from, and hereâs the event procedure:
Private Sub cmdGetNextMaxValue_Click()
Me.txtNextMaxValue.SetFocus
Me.txtNextMaxValue.Text = CStr(GetNextMaxValue)
End Sub
Hope that gets you a little further along. Thatâs a pretty wicked UID youâre working with.
HTH,
Bob
|