?
Solved

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

Posted on 2004-03-27
4
Medium Priority
?
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

770 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