Solved

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

Posted on 2004-10-20
5
168 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 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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