R
RA
I inherited a database and in order to keep from rebuilding it I want to
change the way a value is populated in a form field.
Basically, the form has an order ID (autonumber) and an order number (text
with number) I want to change the order number to a pure number and then
have it figure what number should be next and auto populate it. I thought of
just coping the autonumber value, but having it figure the next number may be
easier.
What would the module command look like?
I have this in another database:
****************************
Option Compare Database
Public Function NextOrderNo() As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT Max(CLng(Mid([Ticket # :], 4))) " & _
"FROM [Routing Details - Table]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
NextOrderNo = "MCO" & rs.Fields.Item(0).Value + 1
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
I hate to mess with what is working, but I am getting complaints about the
text & number field not sorting using the digits as numbers. Ex: MCO1,
MCO11, MCO111, MCO2, MCO3 etc…
change the way a value is populated in a form field.
Basically, the form has an order ID (autonumber) and an order number (text
with number) I want to change the order number to a pure number and then
have it figure what number should be next and auto populate it. I thought of
just coping the autonumber value, but having it figure the next number may be
easier.
What would the module command look like?
I have this in another database:
****************************
Option Compare Database
Public Function NextOrderNo() As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT Max(CLng(Mid([Ticket # :], 4))) " & _
"FROM [Routing Details - Table]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
NextOrderNo = "MCO" & rs.Fields.Item(0).Value + 1
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
I hate to mess with what is working, but I am getting complaints about the
text & number field not sorting using the digits as numbers. Ex: MCO1,
MCO11, MCO111, MCO2, MCO3 etc…