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 / May 2008

Tip: Looking for answers? Try searching our database.

number fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sandrao - 02 May 2008 18:47 GMT
I am trying to get a number field to react as an autonumber. Through
code.

I have seen examoles of this but can't remember where?
Linq Adams - 02 May 2008 19:45 GMT
Here's a typical Auto-incrementing Number hack. The first code here would be
for an IDNumber that is defined in the table as Text datatype. "Number"
fields that aren't used for math really should be defined as Text.  

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
 If RecordsetClone.RecordCount = 0 Then
  Me.IDNumber = "1"
 Else
  Me.IDNumber = DMax("val([IDNumber])", "YourTableName") + 1
 End If
End If
End Sub

Here's the same code for an IDNumber defined as Numerical:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
 If RecordsetClone.RecordCount = 0 Then
  Me.IDNumber = 1
 Else
  Me.IDNumber = DMax("[IDNum]", "YourTableName") + 1
 End If
End If
End Sub

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

 
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.