Results 1 to 3 of 3

Thread: [RESOLVED] [02/03] "Object reference not set to an instance of an object."

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    131

    Resolved [RESOLVED] [02/03] "Object reference not set to an instance of an object."

    I don't know why it's saying this when I try to have the data emailed to me, I copied the code from a working form that I just did.

    vb Code:
    1. Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    2.         If Not emailit() Then
    3.             lblResult.Text = "Error generated during form processing. Please try again."
    4.         End If
    5.     End Sub
    6.  
    7.     Public Function emailit() As Boolean
    8.         Dim sent_ok = False
    9.  
    10.  
    11.         Try
    12.             Dim str As StringBuilder = New StringBuilder
    13.             Dim m As Mail.MailMessage = New Mail.MailMessage
    14.  
    15.  
    16.  
    17.             m.To = "email"
    18.             m.From = txtEmail.Text
    19.             m.Priority = Mail.MailPriority.High
    20.             m.Subject = "Open House Form"
    21.  
    22.             Dim body As String
    23.  
    24.             body &= "Open House" & vbCrLf & vbCrLf
    25.             body &= "First Name: " & txtFirst.Text & vbCrLf
    26.             body &= "Last Name: " & txtLast.Text & vbCrLf
    27.             body &= "Address: " & txtAddress1.Text & " " & txtAddress2.Text & vbCrLf
    28.             body &= "City: " & txtCity.Text & vbCrLf
    29.             body &= "State: " & ddlStates.SelectedValue & vbCrLf
    30.             body &= "ZIP: " & txtZIP.Text & vbCrLf
    31.             body &= "Phone: " & txtAreaCode.Text & txtPhone.Text & vbCrLf
    32.  
    33.  
    34.  
    35.             m.Body = body
    36.             'cc sender so they have a copy
    37.             '  m.Cc = eventClass.ContactEmail
    38.  
    39.  
    40.  
    41.             m.Headers.Add("Priority", "high")
    42.             Mail.SmtpMail.SmtpServer = "localhost"
    43.             Mail.SmtpMail.Send(m)
    44.             lblResult.Text = "Thank you, someone will contact you shortly."
    45.             sent_ok = True
    46.         Catch ex As Exception
    47.             sent_ok = False
    48.  
    49.             Dim merror As Mail.MailMessage = New Mail.MailMessage
    50.             merror.To = "email"
    51.             merror.From = "email"
    52.             merror.Subject = "Event Error"
    53.             merror.Body = ex.Message
    54.             Mail.SmtpMail.SmtpServer = "localhost"
    55.             Mail.SmtpMail.Send(merror)
    56.  
    57.  
    58.         End Try
    59.  
    60.         Return sent_ok
    61.     End Function
    62. End Class

    It detects an error and sends me the message, and the message just says "Object reference not set to an instance of an object.". Everything is the same as the working form I copied it from, other than a few fields that I deleted.


    EDIT: Fixed it, missed one last stupid error.
    Last edited by meef; Oct 12th, 2007 at 12:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width