Сбой строки Dlookup

#ms-access-2013

#ms-access-2013

Вопрос:

По какой-то причине я не могу заставить dlookup работать правильно, я продолжаю получать ошибки. Причиной этого является несоответствие типов данных.

   Option Compare Database
  Private Sub Command131_Click()
  DoCmd.SetWarnings False
  If (Nz(DLookup("LetterSent1Bool", "dbo_T_Volunteers", _
 "VolunteerID = '" amp; Me![VolunteerID] amp; "'"))) > 0 Then

 MsgBox "ERROR !     This Volunteer has already received this Letter ,"
 Else

 DoCmd.OpenQuery "ProduceLettersSixToTwelve", , acReadOnly
 If DCount("*", "dbo_T_SixToTwelveWeeks") > 0 Then

 MsgBox "SUCCESS !    Please Open The Mail Merge Template"

 Else
 MsgBox "ERROR !     No Records Found"
 End If
 End If
 End Sub
  

Ответ №1:

Понял, мне нужно удалить кавычки вокруг amp; Me![VolunteerID]

 Option Compare Database
Private Sub Command131_Click()
DoCmd.SetWarnings False
If (Nz(DLookup("LetterSent1Bool", "dbo_T_Volunteers", _
"VolunteerID = " amp; Me![VolunteerID]))) > 0 Then

MsgBox "ERROR !     This Volunteer has already received this Letter ,"
Else

DoCmd.OpenQuery "ProduceLettersSixToTwelve", , acReadOnly
If DCount("*", "dbo_T_SixToTwelveWeeks") > 0 Then

 MsgBox "SUCCESS !    Please Open The Mail Merge Template"

 Else
 MsgBox "ERROR !     No Records Found"
  End If
 End If
 End Sub