Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL Queries in VBA

Since no answered yet my earlier post, I've been working with sq
queries trying to fix that. Dunno if someone knows about queries in VB
but here we go...

sql = "SELECT * FROM Sección WHERE courseno = '"
Range("Información!B4").Value & "'"
Set rs = cn.Execute(sql)
If Not rs.EOF Then 'No existe
sql = "UPDATE Sección SET section = '"
Range("Información!B3").Value & "' WHERE courseno = '"
Range("Información!B4").Value & "'"
MsgBox sql
Set rs = cn.Execute(sql)

The first query (select) works fine but when trying to do the Updat
query it always give me a syntax error. It seems like a right write
query to me. Same happens with this query:

sql = "INSERT INTO Sección (courseno,section) VALUES('"
Range("Información!B4").Value & "','" & Range("Información!B3").Value
"'"
Set rs = cn.Execute(sql)

Any Idea

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default SQL Queries in VBA

Hi javydreamercsw,

Your second query does not return a recordset, as it is an UPDATE query. So
change this:

sql = "UPDATE Sección SET section = '" &
Range("Información!B3").Value & "' WHERE courseno = '" &
Range("Información!B4").Value & "'"
Set rs = cn.Execute(sql)


to this:

sql = "UPDATE Sección SET section = '" &
Range("Información!B3").Value & "' WHERE courseno = '" &
Range("Información!B4").Value & "'"
cn.Execute sql


and it should work.

That said, you really don't need the first query at all. The second one
will only affect records with the specified courseno anyway, so no need to
make 2 trips to the data source. You could check the recordsaffected
argument's value after the Execute method to see if any records were updated
by the statement.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Since no answered yet my earlier post, I've been working with sql
queries trying to fix that. Dunno if someone knows about queries in
VBA but here we go...

sql = "SELECT * FROM Sección WHERE courseno = '" &
Range("Información!B4").Value & "'"
Set rs = cn.Execute(sql)
If Not rs.EOF Then 'No existe
sql = "UPDATE Sección SET section = '" &
Range("Información!B3").Value & "' WHERE courseno = '" &
Range("Información!B4").Value & "'"
MsgBox sql
Set rs = cn.Execute(sql)

The first query (select) works fine but when trying to do the Update
query it always give me a syntax error. It seems like a right writen
query to me. Same happens with this query:

sql = "INSERT INTO Sección (courseno,section) VALUES('" &
Range("Información!B4").Value & "','" & Range("Información!B3").Value
& "'"
Set rs = cn.Execute(sql)

Any Idea?


---
Message posted from http://www.ExcelForum.com/


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
using web queries M-Kells Excel Discussion (Misc queries) 3 June 3rd 08 01:50 PM
Web Queries Stonewall Excel Discussion (Misc queries) 4 July 23rd 07 03:35 PM
Web Queries nastech Excel Discussion (Misc queries) 0 January 18th 06 12:06 PM
Queries Bean123r Excel Discussion (Misc queries) 0 June 17th 05 12:15 AM
Web Queries Alistair[Data#3] Excel Discussion (Misc queries) 0 May 20th 05 12:39 AM


All times are GMT +1. The time now is 12:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"