Hi all,
thank you for taking time out to read this hope you can help
I have a module which generates an autonumber based on a table content (Tbl:Numbervalues) and a prefix (prefix held in Tbl: TextValues)
the module itself works fine and after every getprefix & getnextnumber it updates the number within numbervalues table to the next unique figure.
However what i want it to do is within my database i want to loop through all the records and update a column based on the getprefix() & getnextnumber()
so at the moment lets say column A has values of SHA000001 (in all 100 records) i want it to loop through those 100 records and update to be SHA(from the prefix table) and 000001 all the way to 000100.
Thank you ever so much for taking time out to look at my query
Hope that makes sense and here is my module code
thank you for taking time out to read this hope you can help
I have a module which generates an autonumber based on a table content (Tbl:Numbervalues) and a prefix (prefix held in Tbl: TextValues)
the module itself works fine and after every getprefix & getnextnumber it updates the number within numbervalues table to the next unique figure.
However what i want it to do is within my database i want to loop through all the records and update a column based on the getprefix() & getnextnumber()
so at the moment lets say column A has values of SHA000001 (in all 100 records) i want it to loop through those 100 records and update to be SHA(from the prefix table) and 000001 all the way to 000100.
Thank you ever so much for taking time out to look at my query
Hope that makes sense and here is my module code
Code:
Public Function GetPrefix() As String
On Error GoTo GetPrefix_ErrorHandler
GetPrefix = DLookup("Value", "TextValues", "Description = ""InvoicePrefix""")
If Len(GetPrefix) <> 2 Then
msgbox "The Invoice Prefix Value in the Text Values Table is not 2 characters long!", vbCritical, "Critical Warning"
End If
Exit_GetPrefix:
Exit Function
GetPrefix_ErrorHandler:
Select Case Err
Case Else: msgbox "ERROR " & Err & ": " & Error
End Select
Resume Exit_GetPrefix
End Function
Public Function GetNextNumber() As String
On Error GoTo GetNextNumber_ErrorHandler
Dim MyWorkspace As Workspace
Dim Mydb As Database
Dim InvoiceNumbers As Recordset
Set Mydb = CurrentDb
Set MyWorkspace = DBEngine.Workspaces(0)
Set InvoiceNumbers = Mydb.OpenRecordset("SELECT DISTINCTROW Description, Value FROM NumberValues WHERE Description=""CurrentNumber""", dbOpenDynaset)
If InvoiceNumbers.EOF Then
msgbox "Their is no Invoice Prefix Value in the Number Values Table!", vbCritical, "Critical Warning"
Else
MyWorkspace.BeginTrans
GetNextNumber = zeros(5 - Len(CStr(InvoiceNumbers!Value))) & CStr(InvoiceNumbers!Value)
InvoiceNumbers.Edit
InvoiceNumbers!Value = InvoiceNumbers!Value + 1
InvoiceNumbers.UPDATE
MyWorkspace.CommitTrans
End If
Exit_GetNextNumber:
InvoiceNumbers.Close
Exit Function
GetNextNumber_ErrorHandler:
MyWorkspace.Rollback
Select Case Err
Case Else: msgbox "Error number " & Err.Number & ": " & Err.Description
End Select
Resume Exit_GetNextNumber
End Function