2013-05-21 31 views
0

此代码生成运行时错误3464 dlookupmatchstr_t。我不明白为什么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 
+0

请告诉我们当'DLookup'发生错误时,'Debug.Print matchstr_t'会给你什么。 – HansUp

+0

[appt date] =#27/05/2013#和[appt time] =#16:00#和[Therapist ID] = 2 – user2405097

+0

当您创建并测试这个新的Access查询时会发生什么? ...'选择*从假的地方[appt date] =#27/05/2013#和[appt time] =#16:00#和[Therapist ID] = 2' ...你可能会得到错误#3464, *“标准表达式中的数据类型不匹配”*如果[Therapist ID]'的数据类型是文本而不是数字。 – HansUp

回答

0

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

似乎有一个数据类型与therid的值不匹配。

+0

[治疗师ID]是我正在使用的表中的字段 - 绑定值是一个整数。 – user2405097

0

在这种情况下,也许你只是缺少一个#

matchstr_t = “[聘任日期] =#” &聘任(J)& “#和[聘任时间] =#” & slottime &“#AND [治疗师ID] = “& therid

+0

debug.print matchstr_t给出 – user2405097