I would appreciate help with the following:
I am trying to perform a DLookUp using a text value from a field in a table that is used in my form along with a date field stored in a table and also used in my form. The idea is to lookup a particular price at a particular date in my Shares table but I am at wits end trying to get the syntax correct. I was able to successfully perform a DLookUp from a Test table using a text field on its own and a date field on its own, but the multiple criteria has me lost. The following is my attempt.
Private Sub ClosePrice_Click()
Dim VarX As String
If IsNull(VarX = DLookup("Close", "Shares", "[ASX Code] = " & Forms!WatchList_Notes!ASX _
& " AND [CloseDate] = #" & Format(Forms!WatchList_Notes!NoteDate, "yyyy-mm-dd") & "#")) Then
MsgBox "No Value Found"
MsgBox Forms![WatchList_Notes]![ASX]
MsgBox Format(Forms![WatchList_Notes]![NoteDate], "yyyy-mm-dd")
Else
VarX = DLookup("Close", "Shares", "[ASX Code] = " & Forms!WatchList_Notes!ASX _
& " AND Format(CloseDate, ""yyyy-mm-dd") = "#" & Format(Forms!WatchList_Notes!NoteDate, "yyyy-mm-dd") & "#)"
Forms![WatchList_Notes].[ClosePrice] = Price
End If
End Sub
The following is the error message:
I will appreciate any help on the subject.
Thanks, David