|
以下是引用bfwz在2005-7-5 18:39:00的发言:
表1如下:
a字段 b字段
110 120
210 220
希望VBA的变量A11=110, B22=220,
请问,怎么写语句?
在你的代码前添加以下代码,然后可以用A(1),B(2)来读取数据。当然只能读不能写。
Dim A() as Integer
Dim B() as Integer
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [表1]
rs.Open stSql, con, adOpenKeyset, adLockOptimistic
ReDim A(rs.RecordCount - 1)
ReDim B(rs.RecordCount - 1)
For i = 0 To rs.RecordCount - 1
A(i) = CInt(rs![A字段])
B(i) = CInt(rs![B字段])
rs.MoveNext
Next i
rs.Close |
|