我在 Access 2010 中使用动态传递查询从后端数据库中检索一条或多条记录。经过多次试验和错误,我剽窃了足够多的正确代码来检索适当的记录,并在 OnLoad 事件期间将它们分配给我的数据表表单上的未绑定文本框。剩下的唯一问题是显示多条记录。我已经验证我正在检索多条记录,但是每条记录的字段的内容会覆盖存储到表单文本框控件的先前值,所以当我希望从任何地方看到时,我总是在数据表中只显示一条记录一到十。
我确定这是一个简单的解决方案。有人可以向我指出吗?
Private Sub Form_Load()
Dim sqlString As String
sqlString = "SELECT Transmitter_ID, Receiver_ID, UTC_Date, Local_Date from Detections"
If Not IsNull(Me.OpenArgs) Then
sqlString = sqlString & " where " & OpenArgs
End If
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As ADODB.Recordset
'Define and open connection
cnn.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=z:\EWAMP\EWAMP_be_dev.sqlite"
cnn.Open
'Define ADO command
cmd.ActiveConnection = cnn
cmd.CommandText = sqlString
'Populate and enumerate through recordset
Set rst = cmd.Execute
If rst.EOF Then
MsgBox "Nothing found...", vbInformation + vbOKOnly
Exit Sub
Else
Do While Not rst.EOF
'// I'm guessing the problem is with my control assignments, here.
Me.cntl_Receiver_ID.Value = rst("Receiver_ID")
Me.cntl_Transmitter_ID.Value = rst("Transmitter_ID")
Me.cntl_UTC_Date.Value = rst("UTC_Date")
Me.cntl_Local_Date.Value = rst("Local_Date")
Debug.Print {Show me the four control values}
rst.MoveNext
Loop
End If
End Sub
干杯!
杜德利