Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / April 2008

Tip: Looking for answers? Try searching our database.

Copy field value.............................FMR

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RA - 15 Apr 2008 20:36 GMT
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…
Dirk Goldgar - 15 Apr 2008 23:17 GMT
>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.
[quoted text clipped - 37 lines]
> text & number field not sorting using the digits as numbers.  Ex: MCO1,
> MCO11, MCO111, MCO2, MCO3 etc…

You could always generate your numbers with leading zeros, so the numeric
part is always the same length:

   If rs.EOF Then
       NextOrderNo = "MCO0000001"
   Else
       NextOrderNo = "MCO" & Format(rs.Fields.Item(0).Value + 1, "0000000")
   End If

You'd have to go back and change the ones you previously created, though, so
that they will sort properly with the others.  An update query could do
that.

Also, the number of digits you specify in your format places a hard maximum
on the number.  For example, 7 digits (as in my example above) gives you a
maximum of 9,999,999 items you can number this way.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.