rickywangca
New Member
- Joined
- Jun 18, 2019
- Messages
- 1
Hi all, I'm trying to figure out this problem with copying a file to a new directory, and then using this new file as the data source for all my tables. The copying subroutine works, but I just can't seem to get the source to connect, either it gives an error or just doesn't run. Here's the code; any help appreciated!!
~~~~~~~~
Code:
Sub FileCopy()
'Declare Variables
Dim FSO As Object
Dim user As String
'Create Object
user = (Environ("Username"))
Set FSO = VBA.CreateObject("Scripting.FileSystemObject")
Call FSO.CopyFile("S:\*source_directory*", "C:\Users\" & user & "\Downloads\", True)
End Sub
~~~~~~~~
Code:
Sub sourceChange()
Application.DisplayAlerts = False
Dim i As Integer
Dim user As String
Dim awc As WorkbookConnection
user = (Environ("Username"))
For i = 1 To ActiveWorkbook.Connections.Count
Set awc = ActiveWorkbook.Connections.Item(i)
With awc.OLEDBConnection
.SourceDataFile = "C:\Users\" & user & "\Downloads\database.accdb"
.SourceConnectionFile = "C:\Users\" & user & "\Downloads\database.accdb"
.connection = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\" & user & "\Downloads\database.accdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Info Validation=False"
.Reconnect
End With
Next i
Application.DisplayAlerts = True
End Sub