Hi,
i find code to do it.
You do no have to create sql in seperate files, you can use command function in adodb properties.
Code:
Sub ExecuteSqlScript()
Dim Script As String
Dim FileNumber As Integer
Dim Delimiter As String
Dim aSubscript() As String
Dim Subscript As String
Dim i As Long
Dim cn As Object
Dim comm As Object
Dim rs As Object
Dim dbConnectStr As String
Dim strSheet As String
Dim strRange As String
Set cn = CreateObject("ADODB.Connection")
Set comm = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
username = GetUsername
pass = getPassword
strConnect = "DRIVER={PostgreSQL Unicode};" & _
"DATABASE=AccessLog;" & _
"SERVER=localhost;" & _
"PORT=5432;" & _
"UID=" & username & ";" & _
"PWD=" & pass & ";" & _
"Trusted_Connection=Yes;"
cn.ConnectionString = strConnect
On Error Resume Next
cn.Open
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
On Error GoTo 0
Set comm.ActiveConnection = cn
rs.ActiveConnection = cn
Delimiter = ";"
FileNumber = FreeFile
Script = "CREATE TABLE public.eventcheck(i int);"
'' Script = String(FileLen(FilePath), vbNullChar)
' Grab the scripts inside the file
'' Open FilePath For Binary As #FileNumber
'' Get #FileNumber, , Script
'' Close #FileNumber
comm.CommandText = Script
comm.CommandTimeout = 0
rs.Open comm
cn.Close
End Sub
Best,
Jacek