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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there VBA code that allows me to copy and paste an Access DB?

Status
Not open for further replies.

drrep

Programmer
Mar 13, 2002
47
0
0
US
I know this can be done manually by a right mouse click. But I was wondering if there exists VBA code that will copy and paste my current DB someplace, I figure without shutting down the current DB if possible.
 
This will do it. Each do loop is just to give time for each procedure to complete befire sending a new command.





Option Explicit

Private Sub Form_Load()
Dim Pausetime, Start, Program


'Load Explorer

Program = Shell("c:\windows\explorer.exe", 1)

' wait for procedure to complete
Pausetime = 5
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

'Copy Db

SendKeys &quot;%d&quot; 'Goto address line

' wait for procedure to complete
Pausetime = 2
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;\dbdirectory&quot;

' wait for procedure to complete
Pausetime = 2
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;{enter}&quot;

' wait for procedure to complete
Pausetime = 2
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;%ea&quot; 'highlight all, or you could put in just the name of the database

' wait for procedure to complete
Pausetime = 2
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;%ec&quot; 'copy

' wait for procedure to complete
Pausetime = 2
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;%d&quot; 'change directories

' wait for procedure to complete
Pausetime = 1
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;c:\new directory&quot; 'change destination directory

' wait for procedure to complete
Pausetime = 1
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop
SendKeys &quot;{enter}&quot;

' wait for procedure to complete
Pausetime = 5
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;%ep&quot; 'paste web site

' wait for procedure to complete
Pausetime = 5
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;a&quot; 'to replace all files

' wait for procedure to complete
Pausetime = 15 ' time to actually paste the file
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop


SendKeys &quot;%f&quot; 'close explorer

' wait for procedure to complete
Pausetime = 1
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

SendKeys &quot;c&quot;

' wait for procedure to complete
Pausetime = 5
Start = Timer ' Set start time.
Do While Timer < Start + Pausetime
DoEvents ' Yield to other processes.
Loop

End

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top