English 中文(简体)
VBA 记录: 为什么我宣布我的阵列,即实地价值参数。
原标题:VBA Recordsets: Why does the way I declare my array, in the Fieldvalue parameters of .addnew, matter?

I ve been trying to dynamically add to a Recordset but I am unable to do so. The .addnew function of a adodb.recordset seems to not allow just any type of array to be passed to it s fieldvalues, values parameters. For example if after setting up your recordset with the appropriate field values you say:

 FieldsArray = array("field1", "field2")
 ValuesArray = array("val1","val2")

 rs.AddNew FieldsArray, ValuesArray

This works!! But if you instead write

 Dim fieldsarray(0 To 1) As String
 FieldsArray(0) = "field1"
 FieldsArray(1) = "field2"
 ValuesArray = array("val1","val2")

 rs.AddNew FieldsArray, ValuesArray

It Fails?!?! (More specifically [Run-Time error 3001 : Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another])

为什么有人在新的参数中宣布实地阵列? 我是否能够让后者工作?

最佳回答

This is because in the first example you are declaring two arrays of VARIANT data type, while in the second example you are declaring STRING arrays.

添加新功能预计会有一个变量阵列。

在你的第二个例子中,将你的第一行改为:

Dim fieldsarray(0 To 1) As Variant

and it should work.

问题回答

暂无回答




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签