Dlookup problem in coding

M

Masoud

I have used Dlookup function in the coding of before update of one control in
my form as below

but my coding does not work properly and gives the error "run-time error
2001", "you

canceled the previouse operation. and it willbe debug for Dlookup.

please help me.





Private Sub DefaultForDocument_BeforeUpdate(Cancel As Integer)
' Disallow update if there's not TRANSMITTAL yet
If IsNothing(Me.TRANSMITTAL) Then
MsgBox "You must select a TRANSMITTAL before you can set Default.", _
vbCritical, gstrAppTitle
Cancel = True
Exit Sub
End If

' Make sure there's only one default
' Check only if setting Default = True
If (Me.DefaultForDocument = True) Then
' Try to lookup another contact set Default
If Not IsNothing(DLookup("DocumentNo", "tblTransmittalls", _
"DocumentNo = " & Me.Parent.DocumentNo & _
" AND TRANSMITTAL <> " & Me.TRANSMITTAL & _
" AND DefaultForDocument = True")) Then
' ooops...
MsgBox "You have designated another TRANSMITTAL as the Default
for this Document." & _
" You must remove that designation before you can mark this
TRANSMITTAL as the Default.", _
vbCritical, gstrAppTitle
Cancel = True
End If
End If
End Sub
 
D

Douglas J. Steele

AFAIK, there's no IsNothing function in Access (unless you've added one of
your own)

Try using IsNull instead.
 
M

Masoud

hello,
thank you, I found my answer in another question about dlookup in the site.
Criteria string was mal-formed I must use some thing like this
Dim strWhere As String
strWhere = "[documentNo] = """ & Me.[documentNo] & """"

while i used like this:

strWhere = "[documentNo] = " & Me.[documentNo]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top