469,275 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Runtime Error 31519

Hello All,

I found some code online (from ADezii -- thanks) to import a .txt file into Access using a Dialog box. When I try and run the code, I am getting the runtime error '31519': You cannot import this file. (**Mod Edit Error occurs on line #22 **)

How can I get rid of this error? Any help is appreciated. Thanks!

The following is what I have:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command43_Click()
  2. Dim fDialog As Office.FileDialog
  3. Dim varFile As Variant
  5. DoCmd.SetWarnings False
  7. 'Set up the File Dialog
  8. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  9. With fDialog
  10.   .AllowMultiSelect = False
  11.   .Title = "Select a Text File to Import"
  12.   .InitialFileName = "C:\*.txt"
  14.   'Clear out any Filters, then Add you own (1)
  15.   .Filters.Add "Text Files", "*.TXT"
  17.   'Show the Dialog. If the Show Method returns True, the User picked
  18.   'at least 1 File, otherwise the User clicked Cancel
  19.   If .Show Then
  20.     For Each varFile In .SelectedItems
  21.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  22.       DoCmd.TransferText acImportFixed, "ImportB", "B", 0
  23.     Next
  24.   Else      'Nothing selected in File Dialog
  25.   End If
  26. End With
  28. DoCmd.SetWarnings True
  29. End Sub
Nov 22 '11 #1
7 8177
32,172 Expert Mod 16PB
You provided a FileName parameter of 0. You can't expect it to work with that information ;-)
Nov 22 '11 #2
Thank you! I am new at VBA. How do I enter a file name argument that still allows the user to select the text file?
Nov 23 '11 #3
32,172 Expert Mod 16PB
Scruffy, you need to consider your posts more carefully before submitting them. If your question makes sense to you I expect it's because you already know what you mean. Without any context or reference point that last bit makes no sense to me at all. 'Allowing the user to select the text file' is not any part of the question I've seen so far.

Nought for two isn't a good average ;-)
Nov 23 '11 #4
My goal is to be able to import files using the Dialog box. The filename parameter is the path to the exact file, right? So what should the filename parameter be so that I can still choose the file I want to import?
Nov 23 '11 #5
32,172 Expert Mod 16PB
So, you're really asking here how to use the return value of the FileDialog object you're using.

Try :
Expand|Select|Wrap|Line Numbers
  1. .SelectedItems(1)
But you probably want to ensure :
Expand|Select|Wrap|Line Numbers
  1. .AllowMultiSelect = False
Alternatively, you can use the code from Select a File or Folder using the FileDialog Object.

If you're still not sure which parameter is which in the DoCmd.TransferText() then it would be the fourth parameter and it's called FileName. Context-Sensitive Help can give you all the details you could want for that though.
Nov 24 '11 #6
Thank you so much, I finally have this portion working.
Nov 28 '11 #7
32,172 Expert Mod 16PB
You're welcome :-)
Nov 28 '11 #8

Post your reply

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

Similar topics

5 posts views Thread by Bob Bamberg | last post: by
reply views Thread by Kamal Dhingra | last post: by
7 posts views Thread by yuanlinjiang | last post: by
2 posts views Thread by Aleksandar | last post: by
3 posts views Thread by Jim Armstrong | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.