Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21183

[RESOLVED] Replacement Database File

$
0
0
I have a program using an older (2002-2003) MS ACCESS (JET) database file (ending in .mdb), I'll call it 'mydatabasename.mdb' for this example.
When the main form starts, it uses tables in that db (located in app.path) to populate several items on the form.
I want to OVERWRITE that .mdb file with a replacement file of the same name (providing an updated db for a customer).
I use a commondialog to browse for the new file, invoked by a menu option in the program.
As the current db 'is in use' (but I can close the connection), how do I overwrite the old .mdb file?

Here is what I have tried, but get permission errors (tried lots of things, this below is the latest).

Code:

Private Sub mnuImportDatabase_Click()
If cnn.State = adStateOpen Then  'cnn is my global variable for my db connection 
cnn.Close
End If
CD1.Flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist
CD1.Filter = "DB Files (*.mdb) |*.mdb"
CD1.ShowOpen 'I browse to the replacement file name mydatabasename.mdb
  If Dir(App.Path & "\mydatabasename.mdb") <> "" Then
      Kill App.Path & "\mydatabasename.mdb"  'this DOES delete the file
  End If
  FileCopy CD1.FileName, App.Path & "\mydatabasename.mdb"  'Permissions error
End Sub


Viewing all articles
Browse latest Browse all 21183

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>