chuckcoleman
Registered User.
- Local time
- Yesterday, 19:33
- Joined
- Aug 20, 2010
- Messages
- 377
Hi, this has been driving me nuts for a day now.
I have a form called Revenue Input Form. When a payment is received, the Lot Number is entered along with two other items and the amount of the payment. If the customer has an email address, there is a button on the form that displays "Email" and when you click on it, everything is fine. The email is created acknowledging their payment and it's sent out. If the customer doesn't have an email address, that same button displays "Print" and a paper receipt is created and printed out. The issue is when the customer doesn't have an email address, the first thing I get is "Invalid Use of Null". After acknowledging the error by clicking on "OK", the program continues, and the receipt is printed. How do I prevent the "Invalid Use of Null" message, and more importantly, I don't know what's causing it so I can prevent it.
Any ideas?
I have a form called Revenue Input Form. When a payment is received, the Lot Number is entered along with two other items and the amount of the payment. If the customer has an email address, there is a button on the form that displays "Email" and when you click on it, everything is fine. The email is created acknowledging their payment and it's sent out. If the customer doesn't have an email address, that same button displays "Print" and a paper receipt is created and printed out. The issue is when the customer doesn't have an email address, the first thing I get is "Invalid Use of Null". After acknowledging the error by clicking on "OK", the program continues, and the receipt is printed. How do I prevent the "Invalid Use of Null" message, and more importantly, I don't know what's causing it so I can prevent it.
Any ideas?
Code:
Private Sub EmailPaymentX_Click()
On Error GoTo EmailPaymentX_Error
Dim PrintToPDF
Dim DestPath As String '
Dim ShowPDF As Boolean '
Dim strHyperlinkFile As String
Dim strSelectedFile As String
Dim strSelectedFileSubDirectory As String
Dim oApp As Object
Dim oEmail As Object
Dim objOutlook As Object
Dim fileName As String
'Dim CustEmail As String
Dim CustEmail As Variant
Dim HasEmail As Variant
Dim Desc As String
Dim BindX As TempVars
Dim IsPrimary As Boolean
Dim Amt As Currency
Dim ChkNbr As String
Dim CheckIsBlank As String
Dim LotNumberX As String
Dim FNameX As String
Dim LNameX As String
Dim Greeting As String
Dim DToday As String
Dim TotPaid As Currency
Dim OwnerLU As String
Dim FNameLU As String
Dim LNameLU As String
Dim FNameLU2 As String
Dim LNameLU2 As String
Dim LotNbrLU As String
TempVars.RemoveAll
TempVars!BindX = Forms![Revenue Input Form]![BindNbrX].Value
DoCmd.RunCommand acCmdSaveRecord
If Me.ButtonLabelXY = "Print" Then
GoTo PrintInvoice
Else
If Me.EmailX <> "" Then
CustEmail = Me.EmailX
Else
CustEmail = 0
End If
DToday = Format(Date, "mmmm dd, yyyy")
LotNbrLU = Me.LotNbrX
If Not IsNull(DLookup("[Owner]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")) Then
OwnerLU = DLookup("[Owner]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")
End If
If Not IsNull(DLookup("[FName]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")) Then
FNameLU = DLookup("[FName]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")
End If
If Not IsNull(DLookup("[LName]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")) Then
LNameLU = DLookup("[LName]", "[Email for Receipt]", "[LotNbr] = '" & Nz(LotNbrLU) & "'")
End If
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(0)
DestPath = "C:\HOA\Receipts\"
DoCmd.SetWarnings False
If IsNull(Me.DateInputX) Then
MsgBox ("You must have a date in the 'Input Date' column. Please enter the date this entered into the system.")
Exit Sub
Else
If IsNull(Me.AmountX) Then
DoCmd.Beep
MsgBox ("You haven't entered an amount for this owner. Please enter an amount in the Amount field.")
Exit Sub
Else
End If
End If
HasEmail = CustEmail
DestPath = "C:\HOA\Receipts\"
strSelectedFile = "C:\HOA\Receipts\" & TempVars!BindX & "-" & [Owner]
strSelectedFileSubDirectory = "\Receipts\" & TempVars!BindX & "-" & [Owner] & ".pdf"
strHyperlinkFile = "C:\HOA\Receipts\" & "#" & strSelectedFile
ShowPDF = False
fileName = Application.CurrentProject.Path & strSelectedFileSubDirectory
DoCmd.SetWarnings True
If Not IsNull(Me.CheckNbrX) Then
CheckIsBlank = " on check number " & Me.CheckNbrX & ". "
Else
CheckIsBlank = ". "
End If
LotNumberX = Me.LotNbrX
If Len(Nz(FNameLU)) = 0 Then
FNameLU2 = ""
Else
FNameLU2 = FNameLU & " "
End If
If Len(Nz(LNameLU)) = 9 Then
LNameLU2 = ""
Else
LNameLU2 = LNameLU
End If
If Len(FNameLU2) = 0 Then
Greeting = LNameLU2
Else
Greeting = FNameLU2
End If
If Me.SentX = True Then
Me.SentX = False
DoCmd.RunCommand acCmdSaveRecord
End If
TotPaid = DLookup("[TotalPaid]", "Total paid for dues ack", "Lot = LotNbrX")
With oEmail
.Recipients.Add HasEmail
.Subject = DLookup("SubName", "Admin Table", "LimitNbr=1") & " Payment Acknowledgement"
.Body = vbCrLf & DToday & vbCrLf & vbCrLf & vbCrLf & OwnerLU & vbCrLf & DLookup("[Mailing Address]", "[Master Table]", "[Lot] = LotNbrX") & vbCrLf & DLookup _
("City", "[Master Table]", "[Lot] = LotNbrX") & ", " & DLookup("State", "[Master Table]", "[Lot] = LotNbrX") & " " _
& DLookup("ZIP", "[Master Table]", "[Lot] = LotNbrX") & vbCrLf & vbCrLf _
& vbCrLf & vbCrLf & "Hi " & Greeting & "," & vbCrLf & vbCrLf & "This email is to let you know we received your payment of " _
& Format([TotPaid], "Currency") & CheckIsBlank & " Your payment was posted to your account for your property" _
& " at " _
& DLookup("[lot Address]", "[Master Table]", "[Lot] = LotNbrX") & " and was for the year " _
& DatePart("yyyy", Me.AssYr) & ". As always, we appreciate your support." _
& vbCrLf _
& vbCrLf & "If you have any questions, don't hesitate to contact me." & vbCrLf _
& vbCrLf & "Sincerely," & vbCrLf _
& vbCrLf & DLookup("OfcFName", "Admin Table", "LimitNbr=1") & " " & DLookup("OfcLName", "Admin Table", "LimitNbr=1") & vbCrLf & vbCrLf
' .Display True
.Send
DoCmd.SetWarnings False
DoCmd.OpenQuery "Update Total Paid for Dues ack Sent"
DoCmd.Close acQuery, "Update Total Paid for Dues ack Sent"
DoCmd.SetWarnings True
DoCmd.Beep
MsgBox ("Your email has been sent.")
End With
DoCmd.GoToRecord , , acNext
End If
Exit Sub
PrintInvoice:
DoCmd.OpenReport "Report for Printing receipt", acViewNormal
Me.Requery
Exit Sub
EmailPaymentX_Exit:
Exit Sub
EmailPaymentX_Error:
MsgBox Err.Description
Resume EmailPaymentX_Exit
End Sub