Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel ODBC Direct Connection to SQL Recordset

Status
Not open for further replies.

DanMan1

Programmer
Dec 3, 2004
8
GB
Hi,

I'm trying to connect to an SQl recordset and update some columns I can connect to the server and return a recordset but I can't update it as its read only any ideas on how to get it read write?

Heres my code:

To connect:
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", "admin", "", dbUseODBC)
Set conHolODBC = wrkODBC.OpenConnection("CMSCon", , False, "ODBC;DSN=Holiday;Description=Holiday;APP=Microsoft® Access;WSID=" & Environ$("computername") & ";DATABASE=Annual Leave;Trusted_Connection=Yes")

to return recordset:
strSQL = "SELECT * FROM AGENT_AVAILABILITY WHERE VACATION_YEAR=" & strDate & " AND AGENT_ID=" & lngAgentID
Set rs = conHolODBC.OpenRecordset(strSQL, dbOpenDynaset)

Any ideas would be appreaciated.

Thanks
 
If you are trying to update tables on a database, it will be permissions on those tables that you need to change

AFAIK, ADO and ODBC have read / write functionality - you just have to write the appropriate SQL and have the appropriate permissions on the tables you want to update...

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Hi Geoff,

For some reason it still doesnt work and tghe permissions are set. If I conect to an access db and then update via a linked table it updates fine.

Cheers

Dan
 
How are you trying to update the table ?

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Using the below:

With rs
.Edit
If blnbook = True Then
!REMAINING = !REMAINING - (lngBookMins / 60)
!Selected = !Selected + (lngBookMins / 60)
Else:
!REMAINING = !REMAINING + (lngBookMins / 60)
!Selected = !Selected - (lngBookMins / 60)
.Update
End If
End With

Any Ideas?
 
Just a note: why updating only in the Else part ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Good point, school boy error. Thanks.

It could be due to the default setting for ODBC direct connections is readonly.

Thanks for your advise Geoff i'll have to play around with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top