Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing text 2

Status
Not open for further replies.

Rubius

Programmer
May 12, 2000
57
CA
Ok I need to import a exported spreadsheet into a table in Access. I am able to import the data from the text file which is delimited and sepereated with commas, only if the field headings are at the top. My deliemma is that when the file is exported, I can't get it to export the proper headings.. What I need to do is make access either accept the file without the headings (which currently gives an error about heading &quot;f1&quot; not existing(which isn't in the file anywhere)) or I need a piece of code that will add a line at the top of that text file with the required headings. Here is my code so far which only works if the proper headings are there:<br><br>Private Sub Button10_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim db As Database<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim file As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Set db = CurrentDb<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If IsNull(Me!FILENAME) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;RESPONSE = MsgBox(&quot;Require a Filename&quot;, 48, &quot;Problem&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.TransferText acImportDelim, , &quot;JOB PICK QTY&quot;, file, True<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;db.close<br>End Sub<br><br>The user types in the file name in a form by the way..<br><br>thanks in advance!
 
did you make a &quot;specification&quot; to import by<br>Do this:<br><br>1. Click the &quot;Tables&quot; tab<br>2. Right click in the white space.<br>3. Click &quot;Import&quot;<br>4. In the &quot;Files of Type&quot; (at the bottom) find your Type &quot;.txt&quot; etc.<br>5. Click the &quot;Import&quot; button<br>6. You have 2 choices here &quot;Delimited&quot; or &quot;Fixed Width&quot; choose the one that applies.<br>7. Click the &quot;Advanced&quot; button (lower left)<br>&nbsp;&nbsp;This is where you specify what to import or not. <br>&nbsp;&nbsp;Study this screen it offers lots of functionality.<br>8. Click &quot;Save As&quot; button to save your Specification. Give it a meaningful name.<br>&nbsp;&nbsp;&nbsp;Also if you want to automate Importing later using VBA you can use the same Specification.<br>9. Click Next and follow the prompts.<br><br><br>Example of VBA Import using Specification.<br><br>DoCmd.TransferText acImportDelim, &quot;Acad Import Specification&quot;, &quot;MyTable&quot;, &quot;C:\Sample.csv&quot;, False <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top