Bhupinder Singh
bhupico at yahoo.com
Thu Mar 1 07:33:22 CST 2007
hi , I am working with MS Access 2000 and Excel. I need to keep track of row number of the record that i have imported from excel using "DoCmd.TransferSpreadsheet" (VBA) As it does not import the rows number. it imports all the records randomly. Apart from this could you pls tell me how can i add a autonumber column to an existing table programiticaly or by a query so that i can call it in my program. as MS Access does not support "identity". Purpose: I am importing more then 300 sheets from different excel files. After improting them to different tables i collate all the data in a singel table. In the collated table I want to know the source row. As i can keep trak of the excel file. from where they are imported .BUT not able to keep track of each record within the sheet. Following is the code snippt. acImport, acSpreadsheetTypeExcel9, strTablename, sXlsFileName, True, StrSheetName & "!" '//Create ID Column sAppendRegionCol = "Alter table [" & strTablename & "] add column [RowID] number" CurrentDb.Execute sAppendRegionCol Dim rst As DAO.Recordset Dim iRowID As Integer 'Dim iCount As Integer Dim sRowIDUpdate As String iRowID = 1 sRowIDUpdate = "Select * from [" & strTablename& "]" Set rst = CurrentDb.OpenRecordset(sRowIDUpdate) rst.MoveFirst Do While (Not rst.EOF) rst.Edit rst.Fields(argRowID).Value = iRowID rst.Update iRowID = iRowID + 1 rst.MoveNext Loop I tried to give the serial number to newly generated table thru the above code. But the records in the newly generated table are not in the same order as they are in the sheet. kindly let me how to tackle with the above problem. Thanx in advance. Bhupinder Singh --------------------------------- Heres a new way to find what you're looking for - Yahoo! Answers