Office中国论坛/Access中国论坛

标题: 如何在模块中添加表字段 [打印本页]

作者: yanwei82123300    时间: 2011-8-26 11:47
标题: 如何在模块中添加表字段
请问问各位老师如何将表中的字段值加到公共模块中
例如:
Function GetP(A As Date) As String
Dim Re As String
If A >= CDate("2011-10-1") And A <= CDate("2011-10-22") Then
Re = "2012_P1"
其中("2011-10-1") 为表1的字段值;("2011-10-22") 为表1的字段值
请问老师如何在模块中书写!谢谢
作者: todaynew    时间: 2011-8-26 14:27
看不懂
作者: yanwei82123300    时间: 2011-8-26 16:12
本帖最后由 yanwei82123300 于 2011-8-26 16:13 编辑

todaynew 老师已经解决了,代码如下:
Function GetP(A As Date) As String
Dim rst, rstItems As DAO.Recordset
Dim n As Integer

Set rstItems = CurrentDb.OpenRecordset("Calendar", dbOpenDynaset)
    Dim Re As String
    If A >= CDate("2011-10-1") And A <= CDate("2011-10-21") Then
         Re = "2012_P1"
         A = Naturally_Date
End If
   
    GetP = Re

End Function

作者: todaynew    时间: 2011-8-26 16:40
yanwei82123300 发表于 2011-8-26 16:12
todaynew 老师已经解决了,代码如下:
Function GetP(A As Date) As String
Dim rst, rstItems As DAO.Re ...

更看不懂了,呵呵。
以下的函数运算结果与你的函数运算结果有什么差异来着?
Function GetP(A As Date) As String
Dim Re As String
If A >= CDate("2011-10-1") And A <= CDate("2011-10-21") Then
    Re = "2012_P1"
End If
    GetP = Re
End Function
作者: yanwei82123300    时间: 2011-8-26 17:13
todaynew 老师我想将CDate("2011-10-1") 变为动态的,我刚刚做的有错误!帮助看看
作者: todaynew    时间: 2011-8-26 17:20
yanwei82123300 发表于 2011-8-26 17:13
todaynew 老师我想将CDate("2011-10-1") 变为动态的,我刚刚做的有错误!帮助看看

呵呵,还是看不懂。
至少应该还需要带入一个参数用以指示Calendar表所在的记录,才可能获得该记录对应的起止日期值吧?
作者: yanwei82123300    时间: 2011-8-26 19:55
todaynew 谢谢帮助,我在试试看




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3