473,471 Members | 4,637 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UPDATE SQL Statement in Excel VBA Editor to update Access Database - ADO - SQL

Hello,
I am trying to update records in my database from excel data using vba
editor within excel.
In order to launch a query, I use SQL langage in ADO as follwing:
------------------------------------------------------------
Dim adoConn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim sConn As String
Dim sSql As String
Dim sOutput As String

sConn = "DSN=MS Access Database;" & _
"DBQ=MyDatabasePath;" & _
"DefaultDir=MyPathDirectory;" & _
"DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" &
_
"PWD=xxxxxx;UID=admin;"

ID, A, B C.. are my table fields
sSql = "SELECT ID, `A`, B, `C being a date`, D, E, `F`, `H`, I, J,
`K`, L" & _
" FROM MyTblName" & _
" WHERE (`A`='MyA')" & _
" AND (`C`>{ts '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "'})"
& _
" ORDER BY `C` DESC"
Set adoConn = New ADODB.Connection
adoConn.Open sConn

Set adoRs = New ADODB.Recordset
adoRs.Open Source:=sSql, _
ActiveConnection:=adoConn

adoRs.MoveFirst
Sheets("Sheet1").Range("a2").CopyFromRecordset adoRs
Set adoRs = Nothing
Set adoConn = Nothing

---------------------------------------------------------------
Does Anyone know How I can use the UPDATE, DELETE INSERT SQL statements
in this environement? Copying SQL statements from access does not work
as I would have to reference Access Object in my project which I do not
want if I can avoid. Ideally I would like to use only ADO system and
SQL approach.

Thank you very much
Nono

Jul 23 '05 #1
1 16829

"Nono" <no**********@yahoo.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello,
I am trying to update records in my database from excel data using vba
editor within excel.
In order to launch a query, I use SQL langage in ADO as follwing:
------------------------------------------------------------
Dim adoConn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim sConn As String
Dim sSql As String
Dim sOutput As String

sConn = "DSN=MS Access Database;" & _
"DBQ=MyDatabasePath;" & _
"DefaultDir=MyPathDirectory;" & _
"DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" &
_
"PWD=xxxxxx;UID=admin;"

ID, A, B C.. are my table fields
sSql = "SELECT ID, `A`, B, `C being a date`, D, E, `F`, `H`, I, J,
`K`, L" & _
" FROM MyTblName" & _
" WHERE (`A`='MyA')" & _
" AND (`C`>{ts '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "'})"
& _
" ORDER BY `C` DESC"
Set adoConn = New ADODB.Connection
adoConn.Open sConn

Set adoRs = New ADODB.Recordset
adoRs.Open Source:=sSql, _
ActiveConnection:=adoConn

adoRs.MoveFirst
Sheets("Sheet1").Range("a2").CopyFromRecordset adoRs
Set adoRs = Nothing
Set adoConn = Nothing

---------------------------------------------------------------
Does Anyone know How I can use the UPDATE, DELETE INSERT SQL statements
in this environement? Copying SQL statements from access does not work
as I would have to reference Access Object in my project which I do not
want if I can avoid. Ideally I would like to use only ADO system and
SQL approach.

Thank you very much
Nono


This seems to be an Access question, not an MSSQL one, so you'll probably
get a better response in an Access or ADO group. But if you can build up a
SELECT statement dynamically, then you should be able to build an UPDATE
also - it's not really clear from your post why this isn't working for you.

Simon
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
0
by: ImraneA | last post by:
Hi there Many thanks to those people who contributed to this group, helped me greatly. Enclose, my code, hope it helps others :- Public Function Export_Excel_9(tbx1 As Variant, tbx2 As...
3
by: C | last post by:
Re: Microsoft Knowledge Base Article - 870669 How to disable the ADODB.Stream object from Internet Explorer You may recently have heard of the vulnarability exposed by Internet Explorer as...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
0
by: Dodong | last post by:
Hi, i am a new vb6 programmer. I would like to know the vb6 code to read excel file and save it to access database. I am using ADO.
1
by: buttons | last post by:
I was given a project to figure out how to use Workforce data stored in Excel spreadsheet (Various Formulas such as Data for ethnicity, gender, new hires, turnover, etc) that can be converted into a...
2
by: p.numminen | last post by:
How I convert an Excel spreadsheet into an Access database? This is Office 2003.
2
by: rlsj | last post by:
I noticed EXCEL can automatically update a list from SharePoint services. Is there a quick and easy way to update a list from an Access query? Is it "better" to create the code in ACCESS...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.