Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-20
5
Medium Priority
?
173 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
  • 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

971 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