View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Open/Close CurrentDatabase

Hydra,

Your first error occurs because no database is open. This is because you
just opened Access programmatically and haven't yet opened a database.

Your second error occurs because you don't specify the full path for the
database, e.g., "C:\Users\doug\Documents\DataCheck"

I think you want something like this:

Sub test()
Dim appAccess As Access.Application

If Dir("C:\Users\doug\Documents\DataCheck.mdb") < "" Then
Kill "C:\Users\doug\Documents\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
With appAccess
.NewCurrentDatabase ("C:\Users\doug\Documents\DataCheck.mdb")
.Visible = True
'*** do your stuff here
.Quit
End With
Set appAccess = Nothing
End Sub

hth,

Doug

"Hydra" wrote in message
...


Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
appAccess.CloseCurrentDatabase

This throws an error that says the expression refers to an object that is
closed or does not exist.

------------------

Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
appAccess.OpenCurrentDatabase ("DataCheck")

Throws an error that says the object is missing or open by another user.

-------------------

Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
appAccess.NewCurrentDatabase ("DataCheck")

Creates a new Database Called "DataCheck" and displays it, Provided
DataCheck does not already exist. If it does exist it throws an error
saying
there is an existing database with that name.

-------------------------------------------------------------------

I want to create this file and populate it with data from an Excel sheet,
But if it already exists then I want to kill it and create a new one from
scratch because the columns of data in the Spreadsheet may change.

Or at very least, open the existing file and empty all the data before I
repopulate it.











__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4157 (20090615) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4160 (20090616) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com