Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileCopy Error

Status
Not open for further replies.

AlexRezid

Programmer
Jul 17, 2003
27
FR
Hi all

I've a problem with FileCopy
Code:
Private Sub SaveMeAll()
    Dim Source As String, Dest As String
    
    Source = "C:\Mes documents\Fichier Client\Client_db.mdb"
    Dest = "C:\Mes documents\Fichier Client\Sauvegarde-" & Day(Now) & "-" & Month(Now) & "-" & Year(Now) & ".mdb"
    
    FileCopy(Source, Dest)
End Sub
The debugger tells me an error on FileCopy syntax, but I can't fount the correct syntax...

Could someone help ?

Thanks

Alex
 
Thanks

It works, but not with an open file... And the file I want to copy is my file .mdb with is launching this script...

How can I do ?

Any Idea ?

Alex
 
I dont know of any way you can copy an open file.
What are you trying to achieve - a backup of your database?

If so why not simply run a batch file which copies the database before running it.

Paddyo
 
Hum...

I write that :
Code:
copy "C:\Mes documents\Fichier Client\Client_db.mdb" "C:\Mes documents\Fichier Client\Client_db_save.mdb"

"C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE" "C:\Mes documents\Fichier Client\Client_db.mdb"

Exit

But it let me a Command window terminated but still open...
How can I do this one to be automatically closed ?

Thanks

AlexRezid
 
You can use an API call to close a command prompt. You will need to know the title of the window, because that is what you will use to iterate through open windows and find the one you want to kill.

1. insert this in a module in the declarations portion:

Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

2. Insert this function in a module:

Public Function KillApp(ByVal WinAppName As String) As Boolean
Dim winHwnd As Long
Dim RetVal As Long

winHwnd = FindWindow(vbNullString, WinAppName)

If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
KillApp = False
Exit Function
End If
Else
KillApp = False
Exit Function
End If

KillApp = True
End Function

call it by using a boolean as the return var:

bRet=KillApp(&quot;Finished&quot;)

where &quot;Finished&quot; is the window title.

 
OR you could use a VBScript to copy the file and start your application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top