upload acces database specific columns from excel which have same but uploaded columns

lebedan

New Member
Joined
Nov 22, 2017
Messages
1
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>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top