[英]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.