By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

Automated Import of Non Access Friendly File

P: 2
I am trying to import a .inf file into access (the file comes from the output of some 3rd party software). I have managed to convert the file by opeing it in notepad and re-saving then a seperate script to open the txt file and import. Both these scripts seem to work well (ish) but is there a better way of doing this? and is there a way of doing this and only having to run a single script?

Copies of the script below.

Any help would be much appreciated (I am fairy new to VB s please be gentle).

Derfer


Playing with script found on this site I have managed to do the following to convert the file into a .txt file:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3. Dim fDialog As Office.FileDialog
  4. Dim varFile As Variant
  5.  
  6. DoCmd.SetWarnings False
  7.  
  8. 'Set up the File Dialog
  9. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  10. With fDialog
  11.   .AllowMultiSelect = False
  12.   .Title = "Select a FluoImager .Inf File to Convert"
  13.   .InitialFileName = "C:\*.inf"
  14.  
  15.   'Clear out any Filters, then Add you own (1)
  16.   .Filters.Add "FluoImager Files", "*.INF"
  17.  
  18.   'Show the Dialog. If the Show Method returns True, the User picked
  19.   'at least 1 File, otherwise the User clicked Cancel
  20.   If .Show Then
  21.     For Each varFile In .SelectedItems
  22.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  23.       dTaskID = Shell("notepad.exe " + varFile, vbNormalFocus)
  24.                 Sleep (2000)
  25.                 SendKeys "%"
  26.                 Sleep (250)
  27.                 SendKeys "F"
  28.                 Sleep (250)
  29.                 SendKeys "A"
  30.                 Sleep (1000)
  31.                 SendKeys "GNPOC Database Import File{ENTER}", -1
  32.                 Sleep (3000)
  33.                 SendKeys "%{F4}"
  34.                 Sleep (1000)
  35.       Next
  36.  
  37.   Else      'Nothing selected in File Dialog
  38.   End If
  39. End With
  40.  
  41. DoCmd.SetWarnings True
  42.  
  43. End Sub
Then I have the following for importing that text file (code taken from another post on this site):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim fDialog As Office.FileDialog
  4. Dim varFile As Variant
  5.  
  6. DoCmd.SetWarnings False
  7.  
  8. 'Set up the File Dialog
  9. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  10. With fDialog
  11.   .AllowMultiSelect = False
  12.   .Title = "Select a Text File to Import"
  13.   .InitialFileName = "C:\*.txt"
  14.  
  15.   'Clear out any Filters, then Add you own (1)
  16.   .Filters.Add "Text Files", "*.TXT"
  17.  
  18.   'Show the Dialog. If the Show Method returns True, the User picked
  19.   'at least 1 File, otherwise the User clicked Cancel
  20.   If .Show Then
  21.     For Each varFile In .SelectedItems
  22.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  23.       DoCmd.TransferText acImportFixed, "GNPOC_Spec", "FI_main_data", varFile, -1
  24.       Next
  25.   Else      'Nothing selected in File Dialog
  26.   End If
  27. End With
  28.  
  29. DoCmd.SetWarnings True
  30.  
  31. End Sub
Feb 7 '08 #1
Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,610
  1. Set a Reference to the Microsoft Scripting Runtime Library.
  2. Rename the *.ini File to *.txt via the following code, making the necessary substitutions:
    Expand|Select|Wrap|Line Numbers
    1. 'Declare appropriate Object Variables
    2. Dim fso As FileSystemObject, fil As File
    3.  
    4. 'Create an Instance of the FileSystemObject
    5. Set fso = New Scripting.FileSystemObject
    6.  
    7. 'Set a Object Variable Reference to the File
    8. Set fil = fso.GetFile("C:\Test\Test.ini")
    9.  
    10. fil.Name = "Test.txt"        'Rename the File
    11.  
C:\Test\Test.ini has been renamed to C:\Test\Test.txt
Feb 7 '08 #2

P: 2
Thanks ADezii - it worked a treat.

I used your code with the file selection stuff I had got off this site and all works well - I knew there had ot be an easier way of doing it.

Derfer
Feb 7 '08 #3

ADezii
Expert 5K+
P: 8,610
Thanks ADezii - it worked a treat.

I used your code with the file selection stuff I had got off this site and all works well - I knew there had ot be an easier way of doing it.

Derfer
Glad it worked out for you.
Feb 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.