【问题标题】:Create query that calculates the due dates using Dlookup创建使用 Dlookup 计算到期日期的查询
【发布时间】:2022-01-08 12:13:21
【问题描述】:

我正在尝试使用我的字段中的一个模块进行查询,以查找培训的频率以及某个员工的培训到期时间。我有一个表格,其中包含所有员工信息(Workday_Excel_Update)以及培训课程编号,他何时注册以及是否完成。我还有第二张表,其中包含所有培训编号(CourseNumbers)、培训应该完成的月份日期和频率(以月为单位)。

我在模块中编写了用作字段的代码,但我不断收到以下错误:

“作为查询参数输入的表达式产生了这个错误: 'Microsoft Access 找不到您在 表达式'"

dlookup的原因是为了找到课程号对应的日期和频率。

CourseNumbers 表具有以下字段: -课程编号 -课程名 -频率(即月-日) -Months(以月为单位的频率,直到再次需要培训)

如果有人能告诉我原因,如果您有解决方案,我将不胜感激。

我的模块查询图像

Function getDueDate(CourseNum As String)


Dim yearCounter As Integer
Dim yearStart As Date
Dim yearNow As Integer
Dim monthFreq As Integer
Dim daysDue As Integer

If Not IsNull(DLookup("[Months]", "CourseNumbers", "CourseNumber = CourseNum")) Then

 
monthFreq = DLookup("[Months]", "CourseNumbers", "CourseNumber = CourseNum")

yearStart = DLookup("[Frequency]", "CourseNumbers", "CourseNumber = CourseNum")

yearCounter = Year(yearStart)

yearNow = Year(Date)

While yearCounter <= yearNow
    
    yearStart = DateAdd("m", monthFreq, yearStart)
    
    yearCounter = yearCounter + (monthFreq / 12)
    
Wend

daysDue = DateDiff("d", Date, yearStart)

Else

daysDue = 0

End If


getDueDate = daysDue

End Function

【问题讨论】:

    标签: vba ms-access dlookup


    【解决方案1】:

    CourseNum 是一个变量。您不要在引号内包含变量。

    您也没有指定 字段 CourseNumber 是文本字段还是数字字段,因此您希望:

    替换"CourseNumber = CourseNum"(在所有3个地方):

    如果是数字字段,替换为:

    "CourseNumber = " & CourseNum 
    

    如果是文本字段,则替换为:

    "CourseNumber = '" & CourseNum & "'"
    

    不相关:如果您的字段是文本,那么您可能不应该将其命名为包含“数字”一词的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 2021-07-06
      • 2018-01-04
      相关资源
      最近更新 更多