powerblade
Registered User.
- Local time
- Today, 14:07
- Joined
- Sep 8, 2015
- Messages
- 16
Hi,
I have product form/table which has productId, productCategorie, productname, etc.
When i want add new product, i select first ProductCategorie ie "10"
Then i made a button to get productID ie: 10001 (10 is categorieID+001)
next add productID if categorie is 10, 10002 en so on.
If categorie = 20, then productID = 20001 next 20002 etc...
This works fine. here is my code:
Module:
button onclick event:
So aboe works fine. But i want if my product table is:
productID - Productname
10 001 a
10 002 b
10 003 c
20 001 d
20 002 e
20 003 f
When i delete ie 10 002 productname b and i want add productname X and productCategorie is 10 the code must look to the product ID's with prefix and if ie
productID - Productname
10 001 a
<= 002 is missing
10 003 c
20 001 d
20 002 e
20 003 f
the new productID and name should: 10 002 X.
So looking to the seqiential number after prefix should allways correct without missing the incremented numbers by 1. If missing, then next productID must that missing number. And if all correct, then use the last number +1.
thanks all in advance
I have product form/table which has productId, productCategorie, productname, etc.
When i want add new product, i select first ProductCategorie ie "10"
Then i made a button to get productID ie: 10001 (10 is categorieID+001)
next add productID if categorie is 10, 10002 en so on.
If categorie = 20, then productID = 20001 next 20002 etc...
This works fine. here is my code:
Module:
Code:
Public Function nextIdString(ByVal nisFieldName As String, ByVal nisTableName As String, ByVal nisPrefix As String) As Variant
nextIdString = Nz(DMax(nisFieldName, nisTableName, "[" & nisFieldName & "] Like '" & nisPrefix & "*'"), nisPrefix & "0")
' nisPrefix & "0" gives you a default value if one is not found in the table
nextIdString = Val(Mid(nextIdString, Len(nisPrefix) + 1)) + 1
' Get next numerical value by looking at the highest value number after the prefix and adding 1
nextIdString = nisPrefix & Format(nextIdString, "000") ' create next string Id
' Create new ID string by concatenating the formated number to te prefix
End Function
button onclick event:
Code:
dim strPrefix as string
strPrefix = Format(Me.categorieID, "0")
If Len(Me.Productid & vbNullString) = 0 Then Me.Productid = nextIdString("Productid", "producten", strPrefix)
So aboe works fine. But i want if my product table is:
productID - Productname
10 001 a
10 002 b
10 003 c
20 001 d
20 002 e
20 003 f
When i delete ie 10 002 productname b and i want add productname X and productCategorie is 10 the code must look to the product ID's with prefix and if ie
productID - Productname
10 001 a
<= 002 is missing
10 003 c
20 001 d
20 002 e
20 003 f
the new productID and name should: 10 002 X.
So looking to the seqiential number after prefix should allways correct without missing the incremented numbers by 1. If missing, then next productID must that missing number. And if all correct, then use the last number +1.
thanks all in advance