我会尽力帮助你的。
我知道您使用向导将 2 个字段放在表单上创建了表单。
不清楚的是您正在使用的视图。
好吧,您的表单可以以不同的方式显示:
- 单一形式
- 连续形式
- 数据表
这是由默认视图属性定义的。
要查看表单的属性,请按 F4 查看属性并选择“表单”作为您要查看的对象。
如果您的表单是单一表单或连续表单,您可以访问您放置在上面的两个字段,只需解决它们。
单击您放在表单上的控件,然后按 F4 以查看控件名称。
案例 1 - 单一表单视图
假设您的控件名为 Text1 (200) 和 Text2 (400),为方便起见,您的表单是单个表单。
所以你可以参考2个控件写的值
Dim intText1 As Integer, intText2 As Integer
intText1 = Me.Text1.Value
intText2 = Me.Text2.Value
.Value 属性不是强制性的,因为它是默认属性。
此时可以用 MsgBox 打印出 intText1,2
MsgBox "Text1 = " & CStr(intText1)+ " - Text2 = " & CStr(intText2)
这将显示 Text1 = 200 - Text2 = 400
案例 2 - 连续表单视图
现在让我们假设您的视图是连续形式。
因此,包含 200 和 400 的字段只是一个,但每条记录(行)是一个重复次数与记录数一样多的表格。
在这种情况下,要访问所有记录并将它们存储到一个数组中,您可以在 Form_Load 事件中使用它(您可以通过控件属性窗口 - F4 访问它)
Option Explicit
Option Base 1 ' Set the base index for vectors to 1
Dim rst as DAO.Recordset ' Define a recordset to allocate all query records
Dim Values as Variant ' Define a variant to allocate all the values
set rst = me.RecordsetClone ' Copy all records in rst
rst.MoveLast ' Go to last record
intNumRecords = rst.RecordCount ' Count records
rst.MoveFirst ' Go back to recordset beginning
ReDim Values(intNumRecords) ' Resize Values to allocate all values
i = 1
Do While Not rst.EOF ' Cycle over all records
Values(i) = rst!FieldName ' FieldName is the name of the field of
' the query that stores 200 and 400
i = i + 1 ' Move to next array element
rst.MoveNext ' Move to next record
Loop
rst.Close ' Close recordset
set rst = Nothing ' Release memory allocated to rst
for i = 1 To intNumRecords ' Show easch value as message box
MsgBox Values(i)
next i
注意事项
请注意,如果您要显示的记录少于 32767 条(您可以存储的带符号的最大整数),则此解决方案有效。
msgbox 要求您在每个值处按 OK。不太舒服。
请告诉我这是不是你要找的东西。
再见,
巫师