Solved

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

Posted on 2004-03-27
4
651 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to add and add vat in excel 9 33
Excel If tests 10 53
How to replace  : with / in excel column 4 48
MS Word Formatting 3 25
Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now