【问题标题】:error with multiple dlookup criteria多个查找条件的错误
【发布时间】:2013-05-16 03:00:53
【问题描述】:

此代码为 dlookupmatchstr_t 生成运行时错误 3464。我不明白为什么matchstr_v 似乎工作正常。有什么优惠吗?目前我要做的就是使用dlookup 来标记约会的重复开始时间。

Dim i, j, clientid, therid As Integer
Dim origin_date, apptdate  As Date
Dim slotday, apptype, venue, matchstr_v, matchstr_t As String
Dim slottime As Date
Dim appt(25) As Date
Dim db As Database
Dim rst As Recordset
Dim test As Variant

origin_date = Date
slotday = Me.slot_day.Value
slottime = Me.slot_time.Value
clientid = Me.Client_ID.Value
therid = Me.Therapist_ID.Value
venue = Me.venue.Value
apptype = "continuation"

slottime = Format(slottime, "Short Time")
For i = 1 To 7
    apptdate = Date + i
    If Weekday(apptdate, 2) = slotday Then
    'set up stuff
    For j = 0 To 25
        appt(j) = apptdate + (j * 7)

        Set db = CurrentDb()
        Set rst = db.OpenRecordset("Dummy")

        Debug.Print "[therapist ID] = " & therid
        matchstr_v = "[appt date]= #" & appt(j) & "# AND [appt time] = #" & slottime & "# AND [venue] = '" & venue & "'"
        matchstr_t = "[appt date]= #" & appt(j) & "# AND [appt time] = #" & slottime & "# AND [therapist ID] = " & therid
        Debug.Print matchstr_t
        If Not IsNull(DLookup("[dummy ID]", "Dummy", matchstr_v)) Then
            ' do more stuff
        ElseIf Not IsNull(DLookup("[dummy ID]", "Dummy", matchstr_t)) Then
            ' do more stuff
        Else
            rst.AddNew
            rst.Fields("appt date") = appt(j)
            rst.Fields("appt time") = slottime
            rst.Fields("Client ID") = clientid
            rst.Fields("Therapist ID") = therid
            rst.Fields("appt type") = "continuation"
            rst.Fields("attendance") = "scheduled"
            rst.Fields("venue") = venue
            'Debug.Print rst.Fields("appt date")
            rst.Update
            test = (DLookup("[dummy ID]", "Dummy", matchstr_v))
            Debug.Print test
        End If
        rst.Close
        db.Close
    Next j
    Else
    End If
Next i

【问题讨论】:

  • DLookup 发生错误时,请告诉我们Debug.Print matchstr_t 为您提供的信息。
  • [appt date]= #27/05/2013# AND [appt time] = #16:00# AND [Therapist ID] = 2
  • 当您创建和测试这个新的 Access 查询时会发生什么? ... SELECT * FROM Dummy WHERE [appt date]= #27/05/2013# AND [appt time] = #16:00# AND [Therapist ID] = 2 ... 如果[Therapist ID] 的数据类型是文本而不是数字,您可能会收到错误 #3464,“条件表达式中的数据类型不匹配”
  • 太棒了。非常感谢 - [Therapist ID] 数据类型在原始表中是“数字”,但是当我创建虚拟对象来玩这些代码时,我没有足够小心地设置数据类型。问题解决了。我会弄清楚如何接受这个答案/评论。

标签: ms-access duplicates vba


【解决方案1】:

[治疗师 ID] 的数据类型是什么?

似乎存在与 therid 的值不匹配的数据类型。

【讨论】:

  • [治疗师 ID] 是我正在使用的表中的一个字段 - 绑定值是一个整数。
【解决方案2】:

在这种情况下,您可能只是缺少一个#

matchstr_t = "[appt date]= #" & appt(j) & "# AND [appt time] = #" & slottime & "# AND [治疗师 ID] = #" &干掉

【讨论】:

  • debug.print matchstr_t 给出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
相关资源
最近更新 更多