Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Numbering in Datasheet view


Message #1 by "Christopher Mohr" <cmohr@b...> on Thu, 24 Jan 2002 22:05:51
I have a form that has a subform in datasheet view. Instead of using the 

autonumber feature and having the chance of records being deleted and 

ending up with holes in my ID field, I want to use the recordcount 

function to create my own numbering system. I have done this with standard 

forms, utilizing a add new record button, but I am having trouble in the 

datasheet view. Can you help?



Thanks,



Chris
Message #2 by "Gregory Serrano" <serranog@m...> on Fri, 25 Jan 2002 13:32:23
Chris,



<< I have a form that has a subform in datasheet view. Instead of using 

the autonumber feature and having the chance of records being deleted and 

ending up with holes in my ID field, I want to use the recordcount 

function to create my own numbering system. I have done this with standard 

forms, utilizing a add new record button, but I am having trouble in the 

datasheet view. Can you help? >>



Why not create a field in your table called "RecNo" or something like 

that?  Then on the form's "On Open" event, sort the records as you see 

fit, and then number them in some kind of loop... roughly:



Set MyDB = DBEngine.Workspaces(0).Databases(0)

Set MyTable = MyDB.OpenRecordset("{Name of Table}", DB_OPEN_DYNASET)



{code to count total recs here}



MyTable.MoveFirst

For i = 1 to TotalRecs

   MyTable("RecNo") = i

   MyTable.MoveNext

Next i

MyTable.Close



When the form opens in datasheet view, the records will be counted and 

numbered sequentially.



Greg


  Return to Index