473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using Execute Method, Update becomes Select Query

34
I'm using the QueryDef and Execute method to update a record in my MySQL backend.

Problem: When the Passthrough update query is defined using QueryDef, it becomes a select query, and I cannot use the Execute Method.

Instance:
The following code is defined as a query called "AddCost"
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblinitiative SET tblinitiative.Estimate = " & Estimate & ", tblinitiative.FinalCost = " & FinalCost & " WHERE (((tblinitiative.InitID)=" & InitID & "));
When I do this:
Expand|Select|Wrap|Line Numbers
  1. CreateSPT "Addcost", str, "ODBC;DATABASE=db;DSN=DB;OPTION=0;PWD=health;PORT=0;UID=user"
  2. Set qdf = db.QueryDefs("Addcost")
  3. qdf.Execute
At the qdf.Execute I get the message cannot execute a Select query. Indeed, looking at the created query, it has become a SELECT query, not an UPDATE query.

Are Update queries considered Select queries? And if so, how can I set it up to use the Execute method as to update a record using passthrough query?

In normal circumstances, not using ODBC, I know I could do it another more simple way, but as I've scoured the web, using a passthrough query and execute methods are the only ways to get around another problem linking MySQL Backend and MS Access Front end.

Help!
Jan 14 '08 #1
3 9096
PianoMan64
374 Expert 256MB
You could just simply do a Docmd.RunSQL and between the " " you would add your Update SQL String.

The other option if you're wanting to control an active Recordset in ADO using MySQL, you would need to do the following code example

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub DemoUpdate()
  3.           Dim cn as ADODB.Connection
  4.           Dim cmd as ADODB.Command
  5.           Dim rs as ADODB.Recordset
  6.  
  7.           Set cn = New ADODB.Connection
  8.           Set cmd = New ADODB.Command
  9.           Set rs = New ADODB.Recordset
  10.  
  11.           With cn
  12.              .ConnectionString = "ODBC;DATABASE=db;DSN=DB;OPTION=0;PWD=health;PORT=0  ;UID=user"
  13.           End with
  14.  
  15.     With cmd
  16.             Set .ActiveConnection = cn
  17.             .CommandText = "{SELECT STATEMENT HERE}"
  18.             .CommandType = adCmdText
  19.     End With
  20.  
  21.    set rs = cmd.execute
  22.  
  23. 'You can also set the rs to the Forms Recordset Object by adding the following line of code
  24.     set me.recordset = rs
  25. end sub
  26.  
Jan 15 '08 #2
RAG2007
34
How do I do Docmd.RunSQL making it Pass-Through?

I'll try the ADO version as well. Which do you think is better/stronger/faster, or is it two ways to get the same result?

Thanks

You could just simply do a Docmd.RunSQL and between the " " you would add your Update SQL String.

The other option if you're wanting to control an active Recordset in ADO using MySQL, you would need to do the following code example

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub DemoUpdate()
  3.           Dim cn as ADODB.Connection
  4.           Dim cmd as ADODB.Command
  5.           Dim rs as ADODB.Recordset
  6.  
  7.           Set cn = New ADODB.Connection
  8.           Set cmd = New ADODB.Command
  9.           Set rs = New ADODB.Recordset
  10.  
  11.           With cn
  12.              .ConnectionString = "ODBC;DATABASE=db;DSN=DB;OPTION=0;PWD=health;PORT=0  ;UID=user"
  13.           End with
  14.  
  15.     With cmd
  16.             Set .ActiveConnection = cn
  17.             .CommandText = "{SELECT STATEMENT HERE}"
  18.             .CommandType = adCmdText
  19.     End With
  20.  
  21.    set rs = cmd.execute
  22.  
  23. 'You can also set the rs to the Forms Recordset Object by adding the following line of code
  24.     set me.recordset = rs
  25. end sub
  26.  
Jan 15 '08 #3
RAG2007
34
The ADO example didn't work, gave me this message:

Run-time error '3709':
Requested operation requires an OLE DB Session object, which is not supported by the current provider.

Is it that MySQL doesn't support this?
Jan 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Thomas Scheiderich | last post by:
Why would you use the Recordset object over the Execute method of getting data from your Sql database. For example, I have the following: Execute Method...
6
by: PG | last post by:
When deleting a row from the database, that id is now missing. So what I'm trying to do is update in a loop (maybe an sql loop if there is one) of all of the id numbers - sort of like renaming...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
5
by: Ilan Sebba | last post by:
When it comes to adding records in related tables, Access is really smart. But when I try to do the same using ADO, I am really stupid. Say I have two parent tables (eg Course, Student) and one...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
9
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post by:
Hi there guys, My doubt is related with MySQL and Transactions (InnoDB) so here it goes: I have a query like this: $query = 'START TRANSACTION; '; $query .= 'UPDATE sections '; $query .=...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.