Solved

Save database used by VB via VB to other location???????

Posted on 2004-10-20
5
170 Views
Last Modified: 2010-05-02
I am using VB6 and want to save a database (access 2000 database) via VB6 which i am using in my program.  The database is open and is used to store info in and i want the user to be able to save the database in a place of there choice but not over writting the one used by the program  by going to file and save as.  There for it really has to copy the database used by the program which is stored in the same folder as the program (app.path) etc.  and save it to another folder of the users choice.
I have got this bit to open the save as box but cant get anyfurther as to get it to atualy save the database.

Private Sub saveas_Click()
Dim sFile As String
 
    With CommonDialog1
        .DialogTitle = "Save As"
        .CancelError = False
        .Filter = "All Files (*.*)|*.*"
        .ShowSave
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        sFile = .FileName
    End With

Can anyone help cheers.

GM
0
Comment
Question by:On_The_Level
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 12360905
You need to copy the .mdb file instead.  Get the location with the Common Dialog control but then use the shell copy command to actually do this.

Leon
0
 

Author Comment

by:On_The_Level
ID: 12360932
ok, how is this done then?
0
 
LVL 4

Accepted Solution

by:
AjithJose earned 50 total points
ID: 12362830
To copy any file you can use two simple ways

1. The built in VB method: FileCopy

FileCopy Source, Destination


    With CommonDialog1
        .DialogTitle = "Save As"
        .CancelError = False
        .Filter = "All Files (*.*)|*.*"
        .ShowSave
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        sFile = .FileName

        FileCopy **YourMDB**, sFile

    End With


2. The Windows API method:

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long


    With CommonDialog1
        .DialogTitle = "Save As"
        .CancelError = False
        .Filter = "All Files (*.*)|*.*"
        .ShowSave
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        sFile = .FileName

        CopyFile **YourMDB**, sFile,0

    End With


If you are want to copy already open database file, Then you have to opt for API method, since VB does not allow you to copy open files

~Ajith
0
 

Author Comment

by:On_The_Level
ID: 12378652
Just one question how would you load the database back up would you use the same method???

Cheers folks
0
 
LVL 4

Expert Comment

by:AjithJose
ID: 12379330

You can use this method to copy any file to anywhere.

But if the target files exists, it will be overwritten. Which is not possible if the database file is open. You have to close the currently open database to load the backed up database



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question