Thanks for the reply... I had thought about using a table that was not dropped each time, however I ran accross some issues with this.
Data is imported weekly and 3 time on month end. (Weekly reports, and two monthly reports.) When I import a txt file into the table, for some odd reason it does not keep the data in the same order as the text file. (??) So I added an autoincrement field to the table. The first text field is 200 char in width and then the autoincrement field. I can sort on the autoincriment field to keep the data in order, which is required to process the data because recordsets are spread accross multiple rows in the report. Well, it turns out that Access will not let you reset an autoincrement field back to 1 when you delete all the data unless you compact and repair. So, I just drop the table with sql: DROP TABLE "tblRawRec" and when the user clicks the "import report" button I add the table with SQL: "CREATE TABLE tblRawRec ([RawRec] Text(200), [RecID] AutoIncrement);" This way the autoincrement is always 1 to the number of records in the report (Usually around 11,000).
So - if you know how to get a text import into a table and keep the data in the same order of the text file, I could use a static table and just delete all the data with SQL statement, import, then number the records with a loop. (This was my first plan of attack, but access keep reordering my data for some reason.)
Or - if you know how to reset an autoincrement field to start at 1 after all the data has been deleted that would work as well.
The Option Setting solved my font issue, so this post really more about data management philosophy...
Here's the code I am using:
Code:
Private Sub cmdImpTxt_Click()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim tbl As DAO.TableDef
Dim RecNo As Long
Dim i As Integer
'Set up working environment...
DoCmd.SetWarnings False
DoCmd.Hourglass True
'Initialize variables
Set db = CurrentDb
i = 0
strSQL = "DROP TABLE tblRawRec;"
'Delete the tblRawRec table if it is still in the db
For Each tbl In db.TableDefs
If tbl.Name = "tblRawRec" Then
db.Execute strSQL
Exit For
End If
Next
'Create a new tblRawRec to import the report...
strSQL = "CREATE TABLE tblRawRec ([RawRec] Text(200), [RecID] AutoIncrement);"
db.Execute strSQL
'Import text report here...
DoCmd.TransferText acImportFixed, "ImpTxtRpt", "tblRawRec", "C:\7966_p1009.txt", False
'Clean-up and exit
Set db = Nothing
Set rs = Nothing
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Sub
Note: the file location is just hard coded for testing...
Thanks for the assistance...