PC Review


Reply
Thread Tools Rate Thread

ADO Connection Opens as Read Only

 
 
adam6b
Guest
Posts: n/a
 
      22nd Apr 2010

Below is the vba I am using to connect to an Access 2007 database from Excel
2007 to import data to a table. The code works well the first time I run it,
but on subsequent runs, it fails at ".AddNew" with a run-time error of 3251.
That sounds like the issue is the connection method, but I think
adOpenDynamic and adLockOptimistic should work... Also, if I run this code
in excel and then try to open my database, it will only open as Read Only. I
am not very familiar with this coding or methodology; I had to copy this
section in. Any thoughts would be appreciated...


Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=<<<FILE LOCATION>>>;Persist Security Info=False;"
Set rs = New ADODB.Recordset
rs.Open "<<<TABLE NAME>>>", cn, adOpenDynamic, adLockOptimistic,
adCmdTable
r = 1
Do While Len(Range("A" & r).Formula) > 0
With rs
.AddNew
.Fields("CO") = Range("A" & r).Value
.Fields("SRC APP") = Range("B" & r).Value
.Fields("ACCOUNT") = Range("C" & r).Value
.Fields("BRANCH") = Range("D" & r).Value
.Fields("TRAN CODE") = Range("E" & r).Value
.Fields("TR") = Range("F" & r).Value
.Fields("TRAN DATE") = Range("G" & r).Value
.Fields("SEQUENCE") = Range("H" & r).Value
.Fields("DATE") = Range("I" & r).Value
.Fields("AMOUNT") = Range("J" & r).Value
.Fields("DESC") = Range("K" & r).Value
.Fields("DOC NO") = Range("L" & r).Value
.Update
End With
r = r + 1
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opens as Read Only Gene Microsoft Excel Misc 4 25th Nov 2008 01:27 PM
A document that isn't read only, randomly opens as read only? =?Utf-8?B?QmFyYmFyYQ==?= Microsoft Word Document Management 0 15th Nov 2005 01:15 PM
DB opens as read-only when another user opens it =?Utf-8?B?U3VzYW4gTA==?= Microsoft Access Security 2 29th Apr 2005 06:42 PM
URL opens as read-only =?Utf-8?B?UmljaCBSYWluZQ==?= Microsoft Word Document Management 0 9th Feb 2005 08:13 AM
Excel ADO connection opens read-only instance of opened Excel Serge L Microsoft Excel Programming 6 23rd Sep 2003 07:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:26 AM.