[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

Access VBA Path Problem on Import

I am trying to do an an import for a dBase III file.  It works fine in Access when I navigate to the file and use the built-in Import.  You can see in my code that I have a Dir run first.  The Dir finds the file fine; yet, the docmd aborts with error 3044, invalid path name.  The variable strPath is a Variant.  (I've also tried String.)

I don't understand how Dir finds the file and considers it ok, but docmd fails.

Can anyone help on this?
If Dir(strPath) <> "" Then
    DoCmd.TransferDatabase acImport, "dBase III", strPath, acTable
  End If

Open in new window

0
vlvawter
Asked:
vlvawter
1 Solution
 
peter57rCommented:
You need to see what is being used.

Insert a
Debug.Print strPath
between lines 1 & 2 and see what appears in the Immediate window.
0
 
coffeeshopCommented:
Does "strPath" contains the full drive/path/filename? Are spaces or special characters used?
0
 
vlvawterAuthor Commented:
strPath is 100% correct.  If it weren't then If Dir(strPath) would not work.  

Yes, there is a spacke in one of the folders in the path.  I adjusted strPath to be chr(34) & strPath & chr(34).  It still didn't work.  I keep coming back to Dir(strPath).  The space is in it, but it still works.

I've stepped through the code with F8.  Dir(strPath) is ok.  The error occurs on the next line.
I've stopped the code and checked strPath with the actual path name.  It matches letter for letter.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
rockiroadsCommented:
dont you need to specify a source tablename?

what is strPath, does it point to a folder or your dbase file?

I would say the file ending with your suffix should be specified in the source table
the database path is then either just the folder or full dbase path

DoCmd.TransferDatabase acImport, "dBase III", strPath, acTable, "nameofmydbffileonly","myaccesstable")

or

DoCmd.TransferDatabase acImport, "dBase III", "c:\placewheremydbasefileis", acTable, "nameofmydbffileonly","myaccesstable")

0
 
rockiroadsCommented:
urm, rogue ) in suggested code
0
 
vlvawterAuthor Commented:
Rockie, Your 2nd option did it.  I had used that earlier, but I had left the filename per se on strPath.  Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now