472,354 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 8771
32,511 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,511 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,511 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,511 Expert Mod 16PB
You're welcome :-)
Nov 28 '11 #8

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

Similar topics

by: Bob Bamberg | last post by:
Hello All, I have been trying without luck to get some information on debugging the Runtime Error R6025 - Pure Virtual Function Call. I am working in C++ and have only one class that is derived...
by: Kamal Dhingra | last post by:
Hi Guys, I am developing an asp.net application .In error handling , I have 2 web.congif files ,one is in Web(which is the virtual directory) ,other i have created in a folder in Web/Admin. The...
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with...
by: yuanlinjiang | last post by:
I am working on converting a win32 console application from VC6 to VC7. My version is Microsoft Development Environment 2003 version 7.1.3088. The code works fine on VC6. it is a console...
by: Aleksandar | last post by:
Hi, I need to convert set of Java classes exported from IBM Modeling environment to C# for implementation. When I invoke JCLA conversion from File->Open->Convert in Visual Studio 2005 it starts...
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
by: JFKJr | last post by:
HI!, I am trying to import an excel file to an Access table using the following code, but I am getting "Run-time error '31519':You cannot import this file" error. Function Import_ExcelFile()...
by: blogman | last post by:
I am getting a Visual studio 2008 IDE application R6034 runtime error. This means that the IDE application is raising the error not the application I am building. This means that Microsoft did not...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.