If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > How to set QueryDef type to dbQUpdate?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-30-04, 12:17
tango tango is offline
Registered User
 
Join Date: Jul 2004
Posts: 4
How to set QueryDef type to dbQUpdate?

In Excel VBA, I've established an ODBC connection to a SQLServer db, and I can do a

successful SELECT query, but I'm having trouble doing an UPDATE query. When I run the

following code, I get the error, "Cannot Execute a Select query."


Dim dbsCurrent As Database
Dim qdfChange As QueryDef
Dim rs1 As Recordset
Dim sqlStmt As String

sqlStmt = "UPDATE DATA_99.dbo.IMINVLOC_SQL SET std_cost = .550000 WHERE

(IMINVLOC_SQL.loc='LYN') AND (IMINVLOC_SQL.prod_cat Not In ('RM','PG'))"

Set dbsCurrent = OpenDatabase("VW")

Set qdfChange = dbsCurrent.CreateQueryDef("", sqlStmt)

With qdfChange
.Connect = "ODBC;DATABASE=DATA_02;DSN=LabelData;UID=sa;PW D="
.Execute
End With

dbsCurrent.Close

Okay, so I guess I need to change the QueryDef type to dbQUpdate, but I can't figure

out how to do this. For example, adding this code produces the error, "Invalid use of

property":
Set qdfChange.Type = dbQUpdate

Has anyone come up with a solution to this? Thank you.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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