I would like write a program in excel with VBA which can upload an acces database from the same already uploaded excel sheet. I'm trying to use SQL statements, but I think it cause a problem because i have already checked the connection and it's connect to a database. Can you help me how to fix the problem? Unfortunately, I have to writte a program in excel, not in acces and i have to also use SQL statments for speed. Please help me!
In the code: hibalista= is the name of the acces table and the name of the excel.
hibalista1= is the name of the excel sheet.
jjj= The columns in acces what i only want modify from the same name column in excel.
Azonosító= it is the ID column in acces and it is also the same in excel. I want to filter in base of this coulmun and check where these are same in excel and acces, after i want to check jjj column in acces and if jjj column changed in excel i just want to modify that field in acces to what is in excels cell. Unfortunately, I ussually get error in SQL statement.
What can i correct in code to work properly?
Thank you in anticipation!
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Private Sub CommandButton7_Click()
'On Error GoTo vege
Dim DBFullName As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim User As String
Dim dbWb As String
Dim dbWs As String
Dim dsh
Dim stSQL
Dim strCode
dbWb = Application.ActiveWorkbook.FullName
dbWs = Application.ActiveSheet.Name
dsh = "[" & Application.ActiveSheet.Name & "$]"
User = CStr(Environ("USERPROFILE"))
DBFullName = User & "\Desktop\Adatbázis1.accdb"
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Connect
MsgBox "Connection is succesfull"
stSQL = "UPDATE [;Database=" & DBFullName & ";].hibalista a " _
& "INNER JOIN [Excel 8.0;HDR=YES;IMEX=2;DATABASE=" & User & "\Desktop\hibalista.xlsm ].[REM hbalista1$] b " _
& "SET a.[jjj] = b.[jjj] " _
& "WHERE (((a.[Azonosító])=b.[Azonosító]));"
Debug.Print stSQL
Connection.Execute stSQL
'vege:
Connection.Close
Set Connection = Nothing
End Sub</code>
In the code: hibalista= is the name of the acces table and the name of the excel.
hibalista1= is the name of the excel sheet.
jjj= The columns in acces what i only want modify from the same name column in excel.
Azonosító= it is the ID column in acces and it is also the same in excel. I want to filter in base of this coulmun and check where these are same in excel and acces, after i want to check jjj column in acces and if jjj column changed in excel i just want to modify that field in acces to what is in excels cell. Unfortunately, I ussually get error in SQL statement.
What can i correct in code to work properly?
Thank you in anticipation!
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Private Sub CommandButton7_Click()
'On Error GoTo vege
Dim DBFullName As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim User As String
Dim dbWb As String
Dim dbWs As String
Dim dsh
Dim stSQL
Dim strCode
dbWb = Application.ActiveWorkbook.FullName
dbWs = Application.ActiveSheet.Name
dsh = "[" & Application.ActiveSheet.Name & "$]"
User = CStr(Environ("USERPROFILE"))
DBFullName = User & "\Desktop\Adatbázis1.accdb"
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Connect
MsgBox "Connection is succesfull"
stSQL = "UPDATE [;Database=" & DBFullName & ";].hibalista a " _
& "INNER JOIN [Excel 8.0;HDR=YES;IMEX=2;DATABASE=" & User & "\Desktop\hibalista.xlsm ].[REM hbalista1$] b " _
& "SET a.[jjj] = b.[jjj] " _
& "WHERE (((a.[Azonosító])=b.[Azonosító]));"
Debug.Print stSQL
Connection.Execute stSQL
'vege:
Connection.Close
Set Connection = Nothing
End Sub</code>