It appears you have extra spaces inside the quotes for the 2nd phrase of the
3rd argument. This could mean that no ID is found, so the result of
DLookup() is null, and the attempt to assign Null to the integer variable
results in Error 94 (invalid use of Null).
Try:
Dim varChkID As Variant
varCktID = DLookup("[ID]", "CktsList", _
"([Site_ID]= " & intSite & ") AND ([Display]= """ & strCktID & """)")
If IsNull(varCktID) Then
MsgBox "Not found"
Else
DoCmd.OpenForm "CktModify", , , "[ID] = " & varCktID
End If
If those quotes don't make sense, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"EJO" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello and thanks!
>
> The following code is causing the error 'invalid use of null', but if I
> use the same parmeters in a regular query, the correct ID is pulled,
> how can I correct for the difference?
>
>
> Dim intCktID As Integer, intSiteID As Integer, strCktID As String
>
> intSiteID = Forms!Site!Text2
> strCktID = Me.CktID
>
> intCktID = DLookup("[ID]", "CktsList", "[Site_ID]= " & intSite & " AND
> [Display]=' " & strCktID & " ' ")
>
> DoCmd.OpenForm "CktModify", , , "[ID] = " & intCktID