简体   繁体   English

使用ADO访问多个文本框中的记录集

[英]Access Recordset in Multiple Textboxes using ADO

I am trying to fill my 31 textboxes with one single recordset containing 31 days (from Jan 1st to Jan 31st). 我试图用一个包含31天(从1月1日到1月31日)的单个记录集填充我的31个文本框。

While it's clear for me how to assign each field of the query to the relevant textbox, it's not clear at all how to assign the several values contained in one single field of the query to multiple textboxes. 虽然我很清楚如何将查询的每个字段分配给相关的文本框,但是还不清楚如何将查询的单个字段中包含的多个值分配给多个文本框。

As for example, this is my starting code: 例如,这是我的起始代码:

Private Sub FillDates() 私人子FillDates()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
ssql = "SELECT PricingDate From RoomCalendar WHERE PricingDate BETWEEN #01/01/2016# AND #31/01/2016# AND RateRoomCombinationId=17"
rst.Open ssql, cnn
Do Until rst.EOF = True

'txt1.Value = rst.Fields!PricingDate 
'txt2.Value = rst.Fields!PricingDate 
'txt3.Value = rst.Fields!PricingDate 

rst.MoveNext
Loop
End Sub

Thank you in advance for your help 预先感谢您的帮助

You can use: 您可以使用:

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim Record As Integer
Dim Records As Integer

Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
ssql = "SELECT PricingDate From RoomCalendar WHERE PricingDate BETWEEN #2016/01/01# AND #2016/01/31# AND RateRoomCombinationId=17"

rst.Open ssql, CNN
rst.MoveLast
rst.MoveFirst
Records = rst.RecordCount
For Record = 1 To Records
    Me("txt" & CStr(Record)).Value = rst.Fields!PricingDate.Value 
    rst.MoveNext
Next
End Sub

Note please, the format for the date expressions. 请注意,日期表达式的格式。

I managed to solve the question on my own. 我设法自己解决了这个问题。 Final code is: 最终代码是:

Private Function FillDates()
Dim cnn As ADODB.Connection
Dim ssql As String
Dim rst As ADODB.Recordset
Set cnn = CurrentProject.Connection
Dim i As Integer
Dim Records As Integer
ssql = "SELECT PricingDate From RoomCalendar WHERE PricingDate BETWEEN #2016/01/01# AND #2016/01/31# AND RateRoomCombinationId=17"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open ssql, cnn
Records = rst.RecordCount
For i = 1 To Records
    Me("Text" & i).Value = rst.Fields!PricingDate.Value
    rst.MoveNext
Next i
   '' Clean up
    rst.Close
    Set rst = Nothing
End Function

Thanks for your help 谢谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM