Hi and Greeting to everyone
i need help with the following and i have try my very best to try out every possible way to add the auto reset into it but how ever i am not able to do so and i am new to vba.
i learn by searching the web but i could not find any best way to do it. and i am learning thru the ms access db northwind
hope that someone could help me out, thanks in advance~!!
Question 1
AO No << table field contain Adjustment Order Number like AO14/02/0001 i need to reset this running number monthly
like example
AO14/02/0001
AO14/02/0002
AO14/02/0003
AO14/03/0001
AO14/03/0002
AO14/03/0003
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, "0000") ' create next string Id
' Create new ID string by concatenating the formated number to te prefix
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strPrefix As String
strPrefix = "AO" & Format(Date, "yy") & "/" & Format(Date, "mm") & "/"
If Len(Me.[AO No] & vbNullString) = 0 Then Me.[AO No] = nextIdString("AO No", "AO", strPrefix)
End Sub
Question 2
i have 5 different type of Order table and a customer table and 3 of the order table is relationship to Customer table
and inventory transaction table is relationship to every order table
tbl PO = Purchase Order
tbl SO = Sales Order
tbl RO = Repair Order
tbl LO = Loan Order
tbl AO = Adjustment Order
tbl Customer = Customer
and each Order number from SO, RO, LO is relationship to Customer
meaning customer can have many order number from each order table link to it
after the relationship is setup to customer table
when i enter customer table it prompt me for subdatasheet. if i set up the subdatasheet i could only link 1 table to it
even with a union sql table it also happen the same thing
so i could only use the above function to and recreate a new table with different form to put all order into 1 order table
so hopefully some one could help me with it and i have attach the DB that i create. please take a look.
i need help with the following and i have try my very best to try out every possible way to add the auto reset into it but how ever i am not able to do so and i am new to vba.
i learn by searching the web but i could not find any best way to do it. and i am learning thru the ms access db northwind
hope that someone could help me out, thanks in advance~!!
Question 1
AO No << table field contain Adjustment Order Number like AO14/02/0001 i need to reset this running number monthly
like example
AO14/02/0001
AO14/02/0002
AO14/02/0003
AO14/03/0001
AO14/03/0002
AO14/03/0003
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, "0000") ' create next string Id
' Create new ID string by concatenating the formated number to te prefix
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strPrefix As String
strPrefix = "AO" & Format(Date, "yy") & "/" & Format(Date, "mm") & "/"
If Len(Me.[AO No] & vbNullString) = 0 Then Me.[AO No] = nextIdString("AO No", "AO", strPrefix)
End Sub
Question 2
i have 5 different type of Order table and a customer table and 3 of the order table is relationship to Customer table
and inventory transaction table is relationship to every order table
tbl PO = Purchase Order
tbl SO = Sales Order
tbl RO = Repair Order
tbl LO = Loan Order
tbl AO = Adjustment Order
tbl Customer = Customer
and each Order number from SO, RO, LO is relationship to Customer
meaning customer can have many order number from each order table link to it
after the relationship is setup to customer table
when i enter customer table it prompt me for subdatasheet. if i set up the subdatasheet i could only link 1 table to it
even with a union sql table it also happen the same thing
so i could only use the above function to and recreate a new table with different form to put all order into 1 order table
so hopefully some one could help me with it and i have attach the DB that i create. please take a look.