Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now