Solved

Error 3011 - object not defined with VBA - using DoCmd.TransferText in a macro

Posted on 2004-03-27
4
656 Views
Last Modified: 2012-05-04
Here is the code.  Please let me know what is wrong.  I tried to run this within Word and / or Excel.  Got the same error.

Sub Main()
Dim ACObject As Object

Set ACObject = CreateObject("Access.Application")
With ACObject
    .OpenCurrentDatabase "c:\testme.mdb", False
    .DoCmd.TransferText acExportDelim, "Alpha Export", "Alpha", "c:\test.txt"
    End With
ACObject.Close
ACObject.Quit
Set ACObject = Nothing
End Sub

Object not defined refers to the c:\test.txt file.


Thanks,
Russ
0
Comment
Question by:RUSS_EMI
4 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 10699392
Russ:
If I were you, I'd place a 20-point "pointer" question in the Access topic area to this Q.
:)
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 10699542
This is copied from another source on the internet....
http://support.cai.com/helpfiles/as61help/ASMGRError_3011.html

Explanation:

There can be several reasons for this error message:

1. The file doesn't exist.

2. The file is in use by another application which has it open in exclusive mode, and the file hasn't been flagged as shareable.

3. You do not have the proper rights to this directory or file.

4. The path to this file is incorrect.


It also suggests that you may want to export everything from your database, recreate it and then re-import.  Perhaps a corrupt db.

0
 

Author Comment

by:RUSS_EMI
ID: 10701230
The file doesn't exist is correct.  I'm trying to export data to it, shouldn't the file "c:\test.txt" be created?  
Changing "Ex"port to "Im"port works; that is, where the file does exist and is populated with data.  
This is on a stand alone machine.  
The db only consists of two fields (1 record); id (autonumber) & field1 ("a").  
I created it.  
Russ
0
 
LVL 6

Accepted Solution

by:
bkpchs237 earned 125 total points
ID: 10710020
RUSS_EMI,

Reading your docmd statement indicates that you have a specification named: "Alpha Export"
and a table named: "Alpha".  What happens if you eliminate the specification?

I ran this modified code and it worked for me just fine after adding a reference to the Access library
thru Tools, References.  I eliminated the Close command as well as it is not supported or necessary.

Sub Main()
Dim ACObject As Object
Set ACObject = CreateObject("Access.Application")
With ACObject
    .OpenCurrentDatabase "c:\testme.mdb", False
    .DoCmd.TransferText acExportDelim, "", "Alpha", "c:\test.txt", False, ""
    End With
ACObject.Quit
Set ACObject = Nothing
End Sub


Hope this helps.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Perhaps more familiar to developers who primarily use VBScript than to developers who tend to work only with Microsoft Office and Visual Basic for Applications (VBA), the Dictionary is a powerful and versatile class, and is useful …
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question