当从Network PC

时间:2016-06-20 10:57:33

标签: vba ms-access

我有一个像当前记录集不支持更新的问题。 Ms-access数据库和excel VBA在同一台PC上完美运行。

如果我访问excel VBA文件并从网络PC链接数据库,它无法正常发生错误,如“当前记录集不支持更新。这可能是提供商的限制”

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim db As Variant
Dim strSQL As String
Dim wSheetName As Variant

db = "\\SIMPLAN-SWATHI\Users\mgt\dbdata.accdb" //Network DB path

cn.ConnectionString = "provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & db
cn.Open
rs.Open "SELECT * FROM T_Booking;", cn, adOpenDynamic, adLockOptimistic

With rs
        .AddNew
        .Fields("部屋ID").Value = Val(Cells(Selection(1).Row, 1))
        .Fields("利用期間開始日").Value = column_to_date(Selection(1).column)
        .Fields("利用期間終了日").Value = column_to_date(Selection(Selection.Count).column)
        .Fields("削除フラグ").Value = False
        .Fields("更新日時").Value = Now
        .Fields("登録日時").Value = Now
        .Update
    End With

//Colot setting of cell
 Selection.Interior.Color = bg_reserve_booking
 Selection.Borders.LineStyle = xlContinuous

 rs.Close
 Set rs = Nothing
 Set cn = Nothing

任何帮助表示赞赏..

0 个答案:

没有答案