【发布时间】:2015-08-26 14:02:06
【问题描述】:
我正在尝试在 access 中创建一个安全的数据库,并在 excel 中创建一个用户表单。我了解所有 VBA 以及从访问 excel 发送和接收数据的大部分语法。我的问题是我只能写入 64 个字段 (0-63) 我有超过 75 列我想在 access 和 excel 之间来回移动。这是我的一些代码,不清楚。
' open the database based on type of save
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ace.OLEDB.12.0; Data Source=" & DBFullName & ";"
Set rs = New ADODB.Recordset
With rs
' open the recordset
'.MaxRecords = 70
.Open "SELECT * FROM " & TableName & " WHERE [Task_Number] = '" & MyCriteria & "'", cn, adOpenKeyset, adLockOptimistic
countfields = .Fields.Count 'Returns 132
.Fields(60).Value = "60" 'Works
.Fields(61).Value = "61" 'Works
.Fields(62).Value = "62" 'Works
.Fields(63).Value = "63" 'Works
.Fields(64).Value = "64" 'Does not work
.Fields(65).Value = "65" 'Does not work
.Fields(66).Value = "66" 'Does not work
.Fields(80).Value = "80" 'Does not work
.Update ' stores the new record
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
.MaxRecords 设置为 0(无限制),但我也尝试将其更改为我需要的记录数以及我的记录集中有多少字段。
【问题讨论】:
-
如果您在 Excel 中创建要存储与该数据库的连接的用户表单,则很难说数据库是安全的。
-
请确认您遇到了什么错误。即“不起作用”是什么意思。
-
如果你做 rs.fields.Count 你会得到什么?
-
请尝试我的答案中的代码
标签: excel vba field ado recordset