user2742754
user2742754

Reputation: 23

Call to a database in the link directory

I am trying to do a VBA SQL call to a database in the link directory

The database is held in Sync drive, but my local link is listed below and correct

When I try open the program it comes up with

Run-time error 3024 - Could not find the File Powershop.mdb

ChDir "C:\Users\User\Sync\Powershop Backups\GI"


ReadOnly = False

'      >>>>> Open Database <<<<<

Set Jet = CreateWorkspace("", "admin", "", dbUseJet)
Set PowerShop = Jet.OpenDatabase("PowerShop.mdb", , ReadOnly)

Upvotes: 0

Views: 28

Answers (1)

HackSlash
HackSlash

Reputation: 5811

Use a With block for database connections so the object always gets cleaned up properly. This makes it so you don't have to manually set Jet = nothing at some point.

Like so:

Dim thePath As String
thePath = "C:\Users\User\Sync\Powershop Backups\GI\"
With Jet.OpenDatabase(thePath & "PowerShop.mdb", , ReadOnly)

    ' Do stuff with the database 

    .Close
End With

Upvotes: 1

Related Questions