Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Error 3051 - Cannot open file in Access


(!)

gfg's Avatar
gfg gfg is offline
Senior Member with 128 posts.
THREAD STARTER
 
Join Date: Aug 2005
Location: Atlanta, GA
Experience: Intermediate
14-May-2008, 12:37 PM #1
Error 3051 - Cannot open file in Access
I have export code in Access 2003 that creates an Excel export.

It works fine in XP pro - does not work in Vista business

I get the message:

The Microsoft Jet database engine cannot open the file c:\Users\Ansley\Documents\05_08_08.xls. It is already opened exclusively by another user, or you need permission to view it's data.


Here is the code:


Public Function ExportFile(ExportType As String) As Boolean

Dim strSQL As String
Dim DPath As String
Dim sl As String
Dim response As String
Dim Complete As Boolean


DPath = "C:\Users\Ansley\Documents\"

DoCmd.SetWarnings False

strSQL = "DELETE tblExport_1.* FROM tblExport_1;"
DoCmd.RunSQL (strSQL)

response = MsgBox("You are going to create an export in Excel. Do you want to continue?", vbYesNo, "Export")
If response = vbYes Then
FName = InputBox(Prompt:="What file name do you want to use?", _
Title:="File Name", Default:=Format(Date, "MM_DD_YY") & ".xls")
If FName = "" Or IsNull(FName) Then
MsgBox "Exiting - no file name given.", vbCritical
Exit Function
End If
Path = InputBox(Prompt:="Where do you want to save the file?", _
Title:="File Path", Default:=DPath)

If Path = "" Or IsNull(Path) Then
MsgBox "Exiting - no path given.", vbCritical
Exit Function
End If

DoCmd.SetWarnings False

If Nz(ExportType, "") = "Standard" Then

If Me.chkGift = -1 Then
DoCmd.OpenQuery "qryExport_3"
Else
DoCmd.OpenQuery "qryExport_1_NoGift"
End If
Else
If ExportType = "Entered" Then DoCmd.OpenQuery "qryGiftsEnteredToday"
If ExportType = "Received" Then DoCmd.OpenQuery "qryGiftsReceivedToday"
End If

DoCmd.SetWarnings True
DoCmd.TransferSpreadsheet acExport, , "tblExport_1", Path & FName, True

MsgBox "Table " & FName & " " & "Exported to " & Path, vbInformation, "Export Information"

Else
MsgBox "Did not create export.", vbCritical
End If


DoCmd.SetWarnings True

ExportFile = Complete

Exit_cmdExport_Click:
Exit Function

Err_CmdExport_Click:
MsgBox Err.Description
Resume Exit_cmdExport_Click

DoCmd.SetWarnings True
End Function


Any suggestions? I do not think it has anything to do with security or rights.


Thanks
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,616 posts.
 
Join Date: Mar 2005
Location: UK
14-May-2008, 12:55 PM #2
You have to be very carefull of Permissions in Vista compared to XP Pro, so it could be the Folder permissions.
Have you run this code once or twice.
I have noticed that Access VBA quite often leaves the Excel file open and unobtainable to everything except VBA, but it can even stop that using it.
Have you completely closed down the computer and run the code again?
__________________
OBP
I do not give up easily
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,616 posts.
 
Join Date: Mar 2005
Location: UK
14-May-2008, 01:03 PM #3
Does the Excel File exist?
Is it created?
gfg's Avatar
gfg gfg is offline
Senior Member with 128 posts.
THREAD STARTER
 
Join Date: Aug 2005
Location: Atlanta, GA
Experience: Intermediate
14-May-2008, 01:13 PM #4
the file does not exist

the funny part is that the code ran once last week, and then stopped working

the default file name is the current date - so it is a new name every day, at least one time, and it never created this file.

The folder is owned by the user - so I cannot understand why it would be a security issue

I heard that it could be related to the registry - that certain file types are restricted in Access 2003 - but it works on my XP PC.
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,616 posts.
 
Join Date: Mar 2005
Location: UK
14-May-2008, 01:23 PM #5
I notice that you are putting it in c:\Users\Ansley\Documents, Vista may not give Access rights to that Folder as it belongs to Ansley, who is presumably you.
Have tried changing the code to put the file directly on Drive C:
gfg's Avatar
gfg gfg is offline
Senior Member with 128 posts.
THREAD STARTER
 
Join Date: Aug 2005
Location: Atlanta, GA
Experience: Intermediate
14-May-2008, 01:26 PM #6
Oh how I love Vista :-(

I am logged in as Ansley when I try to run this code

I have tried c:\ with the same results
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,616 posts.
 
Join Date: Mar 2005
Location: UK
14-May-2008, 01:36 PM #7
I get exactly the same error & message, so it is not just you or your computer, I am sure that it is something to do with Vista.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
How do I open .zip file in Windows Vista? Getting msgs access rovaira Windows Vista 4 29-Sep-2007 12:30 AM
Networked Access File wont Open fingerz Business Applications 2 27-Nov-2006 05:09 PM
Access 2000 mdb file will not open knox750 Business Applications 6 20-Mar-2006 11:36 AM
Access 2003 stops responding when I open a database file Loyal Business Applications 2 22-Apr-2005 06:47 AM
Unable to access control panel or open file folders. firefreeman Earlier Versions of Windows 2 26-Nov-2004 09:44 PM

WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑