Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Can't kill 'e can't live with 'em.

If Dir(strDB) < "" Then
Kill strDB
End If

Set AppAccess = CreateObject("Access.Application")
AppAccess.Visible = True
AppAccess.OpenCurrentDatabase strDB
AppAccess.DoCmd.Opentable "MSP Data", acViewNormal, acAdd

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

Throws an Error cannot open the database because it is missing or opend
exclusively by another user


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


If Dir("C:\DataCheck.mdb") < "" Then
MsgBox "Datacheck Exists"
Kill "C:\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
..NewCurrentDatabase ("C:\DataCheck.mdb")
..Visible = True

---------------------------------------------
Throws an error saying there is an existing database with this name, choose
another name.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Can't kill 'e can't live with 'em.

Try it this way:

If Not Dir(strDB) Is NothingThen



"Hydra" wrote in message
...
If Dir(strDB) < "" Then
Kill strDB
End If

Set AppAccess = CreateObject("Access.Application")
AppAccess.Visible = True
AppAccess.OpenCurrentDatabase strDB
AppAccess.DoCmd.Opentable "MSP Data", acViewNormal, acAdd

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

Throws an Error cannot open the database because it is missing or opend
exclusively by another user


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


If Dir("C:\DataCheck.mdb") < "" Then
MsgBox "Datacheck Exists"
Kill "C:\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
.NewCurrentDatabase ("C:\DataCheck.mdb")
.Visible = True

---------------------------------------------
Throws an error saying there is an existing database with this name,
choose
another name.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Can't kill 'e can't live with 'em.

This threw a type mismatch error ???

strDB is Dim as string and contains the name of a valid path.



"JLGWhiz" wrote:

Try it this way:

If Not Dir(strDB) Is NothingThen



"Hydra" wrote in message
...
If Dir(strDB) < "" Then
Kill strDB
End If

Set AppAccess = CreateObject("Access.Application")
AppAccess.Visible = True
AppAccess.OpenCurrentDatabase strDB
AppAccess.DoCmd.Opentable "MSP Data", acViewNormal, acAdd

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

Throws an Error cannot open the database because it is missing or opend
exclusively by another user


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


If Dir("C:\DataCheck.mdb") < "" Then
MsgBox "Datacheck Exists"
Kill "C:\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
.NewCurrentDatabase ("C:\DataCheck.mdb")
.Visible = True

---------------------------------------------
Throws an error saying there is an existing database with this name,
choose
another name.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Can't kill 'e can't live with 'em.

I just ran this, and it deleted the file. The two message boxes are
trouble shooting tools and can be deleted or ignored. It is basically the
same code that you initially posted, so it could be that someone had the
file open. Or maybe you had the file open. It will not delete an open
file.

Sub dk()
myPath = ThisWorkbook.Path
fl = myPath & "\test.xls"
If Dir(fl) < "" Then
MsgBox "It's There"
MsgBox Dir(fl)
Kill fl
End If
End Sub

And yes, the syntax using the Not operator will not work for this
application. I leaped before I looked on that one.


"Hydra" wrote in message
...
This threw a type mismatch error ???

strDB is Dim as string and contains the name of a valid path.



"JLGWhiz" wrote:

Try it this way:

If Not Dir(strDB) Is NothingThen



"Hydra" wrote in message
...
If Dir(strDB) < "" Then
Kill strDB
End If

Set AppAccess = CreateObject("Access.Application")
AppAccess.Visible = True
AppAccess.OpenCurrentDatabase strDB
AppAccess.DoCmd.Opentable "MSP Data", acViewNormal, acAdd

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

Throws an Error cannot open the database because it is missing or opend
exclusively by another user


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


If Dir("C:\DataCheck.mdb") < "" Then
MsgBox "Datacheck Exists"
Kill "C:\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
.NewCurrentDatabase ("C:\DataCheck.mdb")
.Visible = True

---------------------------------------------
Throws an error saying there is an existing database with this name,
choose
another name.







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Can't kill 'e can't live with 'em.

if the first IF/End If deletes the file if it exists, and then the second
block of code tries to open the file, so it must fail....hence the error.


"Hydra" wrote in message
...
This threw a type mismatch error ???

strDB is Dim as string and contains the name of a valid path.



"JLGWhiz" wrote:

Try it this way:

If Not Dir(strDB) Is NothingThen



"Hydra" wrote in message
...
If Dir(strDB) < "" Then
Kill strDB
End If

Set AppAccess = CreateObject("Access.Application")
AppAccess.Visible = True
AppAccess.OpenCurrentDatabase strDB
AppAccess.DoCmd.Opentable "MSP Data", acViewNormal, acAdd

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

Throws an Error cannot open the database because it is missing or opend
exclusively by another user


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


If Dir("C:\DataCheck.mdb") < "" Then
MsgBox "Datacheck Exists"
Kill "C:\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
.NewCurrentDatabase ("C:\DataCheck.mdb")
.Visible = True

---------------------------------------------
Throws an error saying there is an existing database with this name,
choose
another name.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill a File Posse John Excel Programming 2 August 4th 06 02:23 PM
Kill Michael Excel Programming 2 August 23rd 05 11:53 AM
'Kill' solomon_monkey Excel Programming 7 January 7th 05 09:56 AM
File kill help Marino13[_6_] Excel Programming 0 February 19th 04 01:40 PM
scrollbar control of a chart, live or not live Brian Murphy[_2_] Excel Programming 2 January 9th 04 11:31 PM


All times are GMT +1. The time now is 08:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"