Hi, I need to update this code to check if there are no first records (table empty) it should create it. Now it gives an error that it does not find first record and stops if table has no records.
Also the prefix IMK- on line " FindMax = "IMK-" & (mx + 1)" could it be defined in a table because I have to make new module for every table.
I would like to have table named increment with column prefix. I would write then IMK- BO- ORD-
The the module would pick what to write depending on form. If active form IMK then prefix should be taken from table increment IMK-
If active form BO then prefix should be taken from table increment Bo-
any ideas?
PHP:
Function FindMax()
Dim db As DAO.Database
Dim mx As Integer
Dim rs As DAO.Recordset
Dim rsVal As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("ppk", dbOpenDynaset)
rs.MoveFirst
rsVal = rs.Fields("[Pinigu priemimo kvitas Nr:]").Value
' Set mx equal to the numeric portion of the field.
mx = Right(rsVal, Len(rsVal) - 4)
' Loop to make sure you have the maximum number.
Do While Not rs.EOF
rsVal = rs.Fields("[Pinigu priemimo kvitas Nr:]").Value
If Right(rsVal, Len(rsVal) - 4) > mx Then
mx = Right(rsVal, Len(rsVal) - 4)
End If
rs.MoveNext
Loop
' Increment the maximum value by one and
' combine the text with the maximum number.
FindMax = "IMK-" & (mx + 1)
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Function
Also the prefix IMK- on line " FindMax = "IMK-" & (mx + 1)" could it be defined in a table because I have to make new module for every table.
I would like to have table named increment with column prefix. I would write then IMK- BO- ORD-
The the module would pick what to write depending on form. If active form IMK then prefix should be taken from table increment IMK-
If active form BO then prefix should be taken from table increment Bo-
any ideas?
Last edited: