Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup not working if data is data is blank

Status
Not open for further replies.

nmapeso

Technical User
Aug 26, 2005
28
0
0
US
Hello everyone,
I have a email function where to Dlookup the to: and Cc: on a table tblDivision. For some reason if cc is blank on table is not working. If data exsit works okay. I try to use if stCC = "" or Null still not working
Here is my code, works okay if stTo and stCC are not blank
~~~~~~~~~~~~~~~~~~
Private Sub cmdEmailNotification_Click()

On Error GoTo Err_cmdEmailNotification_Click

Dim Subject As String
Dim stDocName As String
Dim strWhere As String
Dim SQL As String
Dim stTo As String
Dim stCC As String


stDocName = "rptMainNotification"
Subject = "Bankruptcy " & "Case Number:" & " " & UCase(CaseNumber) & " Debtor Name:" & " " & DebtorName
stTo = DLookup("Alias", "tblDivision", "Coordinator=" & Chr(34) & Me.Copies & Chr(34))
stCC = DLookup("BAlias", "tblDivision", "Coordinator=" & Chr(34) & Me.Copies & Chr(34))


'Display only current selected ID
strWhere = "[ID]=" & Me!ID
'Update Email Date Sent field
DoCmd.SetWarnings (False)
SQL = "UPDATE maintblBankruptcy SET DateESent = Date()" & _
"WHERE Relationship = '" & Me.Relationship & "'"
'DateESent is Null AND
DoCmd.RunSQL SQL
DoCmd.OpenReport stDocName, acPreview, , strWhere, acHidden
If stCC = "" Then
DoCmd.SendObject acSendReport, stDocName, "Snapshot Format", stTo, , , Subject, "Bankruptcy Notification, open attachment"
Else
DoCmd.SendObject acSendReport, stDocName, "Snapshot Format", stTo, stCC, , Subject, "Bankruptcy Notification, open attachment"
End If
DoCmd.Close acReport, stDocName

Exit_cmdEmailNotification_Click:
Exit Sub

Err_cmdEmailNotification_Click:

Resume Exit_cmdEmailNotification_Click
End Sub
 
You don't say whether you get an error message of the fields are blank, or whether the fields are just empty.
If the DLookup returns NULL you'll get an error assigning that value to a string variable. Wrap the Dlookup in an NZ to allow for this...
strMyvar = nz(DLookup(....),"")
 
Sorry, I don't get any error when click on Email, it just don't open the email or do anything.
 
I wrap it with Nz and works okay. Thank You so much.
 
Looking at your code, if you get an error the function will exit without a message (and appear to do nothing).

To debug, place a Msgbox line in the error handler so you can see if there is an error...

Err_cmdEmailNotification_Click:
msgbox "Error! " & err.number & " : " & err.description
Resume Exit_cmdEmailNotification_Click
End Sub

Without seeing the message it's difficult to identify the failure but my money is on the DLookup as suggested in my first reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top