简体   繁体   English

如何使用数组循环遍历我的记录集?

[英]How do i looping through my recordset using an array?

I would like my function to open the table, and return 1/1/2013 for recordcount 1, 1/2/2013 for recordcount 2 ... 1/20/2013 for record count 20.我希望我的函数打开表,并为记录数 1 返回 1/1/2013,为记录数 2 返回 1/2/2013 ...为记录数 20 返回 1/20/2013。

so far I have the following code but it only return 1/2/2013 and I have 24 records: (My recordcount will vary from 22 -30 each month)到目前为止,我有以下代码,但它只返回 1/2/2013 并且我有 24 条记录:(我的记录数每月从 22 -30 不等)

Public Function DDate() As Date

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim icounter As Integer
Dim UpBound As Long


Set db = CurrentDb()
Set rs = db.OpenRecordset("tblDDate", dbOpenDynaset)


    If Not (rst.BOF And rst.EOF) Then
        rst.MoveFirst

        UpBound = rs.RecordCount

    Do Until rs.EOF = True

        For icounter = 1 To UpBound
            DDate = DateAdd("m", icounter, "1/1/2013")
            rst.MoveNext
        Next icounter
    Loop
    End If

rs.Close
db.Close

 End Function

Your comment above says that the table doesnt contain a date but that you are trying to add a date field to the table.您上面的评论说该表不包含日期,但您正在尝试向该表添加日期字段。

Unfortunately you cannot add a new field (column) to a table like this.不幸的是,您无法向这样的表添加新字段(列)。 You'll need to do that either in design view, or running an ALTER statement on the database at runtime:您需要在设计视图中执行此操作,或者在运行时在数据库上运行 ALTER 语句:

ALTER TABLE myTableName ADD COLUMN dateColumnName Date Null;

then if you want to set the value of the column, hopefully your table has a unique id with the datatype counter(?) I'd recommend you to use an update query:那么如果你想设置列的值,希望你的表有一个唯一的 id 和数据类型 counter(?) 我建议你使用更新查询:

UPDATE myTableName SET dateColumnName = CDate("1/" & trim(uniqueIDColumnName) & "/2013");

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

相关问题 通过循环记录集访问 vba 数组 - access vba array by looping through recordset 遍历记录集时从数组项分配属性 - Assigning an atribute from an array item while looping through a recordset 如何一次向一个数组添加(推送)项目(循环遍历数组) - How do I add (push) items to an array one at a time (looping through array) 在 Javascript 中,循环对象数组时,如何将每个元素的名称发送到控制台? - In Javascript, when looping through an array of objects, how do I send each element's name to the console? 使用ColdFusion循环遍历数组 - Looping through an array using ColdFusion 遍历数组后如何调度? - How do you dispatch after looping through an array? 如何使用watch禁用循环数组的可用时间? - How to disable available times looping through an array using watch? 在数组中遍历JSON对象时,为什么会出现语法错误? 如何正确提取JSON? - Why am I getting a Syntax Error when looping through JSON Objects in an array? How do I extract JSON correctly? 淘汰赛未遍历我的可观察数组 - KnockoutJs not looping through my observable array 使用 JavaScript 使用 if then 语句循环遍历数组 - Looping through an array using if then statements using JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM