|
-
Jan 27th, 2012, 06:07 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Using Constructor Event Creates Errors...
I created an even on a form called Sub New so I can handle some events and close the window down if there is an error.
Upon doing that, I came across 3 errors that I don't know how to fix.
vb.net Code:
Me.Hide()
frmEmail.SetReportDate = #1/23/2012#
frmEmail.Show()
frmEmail.Dispose()
Me.Show()
I get 3 errors, on lines 3, 4 and 5
Reference to a non-shared member requires an object reference
How can I fix this? Note: ShowDialog really isn't necessary I could just use .Show. I want to use ShowDialog because the line under those 3 shows the current form.
Found the problem (I had private sub new) but now a new problem...
How do I pass the date to the form?
In case it's relavent, my code for sub new on frmEmail.
vb.net Code:
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim strHTML As String = String.Empty
Dim Subject As String = "Service Assignments for " & ReportDate.ToString(myDateFormat)
Dim oApp As Outlook._Application
Dim oMsg As Outlook._MailItem
Dim YesNo As DialogResult = Windows.Forms.DialogResult.Yes
Dim NoErrors As Boolean
Me.Text = "Service Assignments for " & ReportDate.ToLongDateString
setHeader()
NoErrors = setData()
setFooter()
strHTML = reportHeader & reportData.ToString & reportFooter
oApp = New Outlook.Application()
oMsg = CType(oApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
oMsg.Subject = Subject
oMsg.HTMLBody = strHTML
oMsg.To = "DTGOn-RentHelpDesk"
oMsg.Importance = Outlook.OlImportance.olImportanceHigh
oMsg.Display()
YesNo = MessageBox.Show("Did the email show up?", Application.ProductName, _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1)
If Not NoErrors Then
Me.Close()
Else
If YesNo = Windows.Forms.DialogResult.No Then
ieWeb.Document.Write(strHTML)
Me.Show()
Else
MessageBox.Show("Push Send in the email window to send!", "Send Email Alert", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
NoErrors = False
oMsg2 = oMsg
End If
End If
End Sub
Last edited by TrickyNick; Jan 27th, 2012 at 06:21 AM.
-
Jan 27th, 2012, 06:26 AM
#2
Re: Using Constructor Event Creates Errors...
The error speaks for itself really; you have a non-shared member, and you are trying to access it without using an object reference.
You must create an instance of frmEmail, then you can use the non-shared members on that instance.
-
Jan 27th, 2012, 06:28 AM
#3
Re: Using Constructor Event Creates Errors...
About your date-passing question. You seem to be passing a date to the form already (provided that you also fix the thing I mention above), what is not working for you?
-
Jan 27th, 2012, 07:26 AM
#4
Thread Starter
Addicted Member
Re: Using Constructor Event Creates Errors...
I am getting that error with the code you see...
when I change to
vb.net Code:
Dim frm As frmEmail Me.Hide() frm.SetReportDate = #1/23/2012# frm.Show() frm.Dispose() Me.Show()
I get an error saying that I'm using before being assigned a value...
if I define it as New frmEmail, then it'll call my code in the New Event but it won't have the date because it hasn't reached that line
I guess my question is, how do I use this code
Dim frm As New frmEmail
and pass it the date?
-
Jan 27th, 2012, 07:37 AM
#5
Thread Starter
Addicted Member
Re: Using Constructor Event Creates Errors...
The basic outline of the way I want them to be handled...
Click on button to email...
gets report data
open an outlook email & put info there
Ask user if outlook email opened,
...if yes, remind user to click on send, close window without ever showing up
...if no, show form with a webbrowser showing the info that way & user manually opens up outlook email
My code is in Public Sub New on frmEmail, I don't want the form to briefly flicker if everything works right. It was working before perfectly, but the form flickered. I'm dealing with non-computer people and they will think something went wrong.
-
Jan 27th, 2012, 08:29 AM
#6
Hyperactive Member
Re: Using Constructor Event Creates Errors...
You can make another constructor that allows you to pass the date.
Code:
Dim frm As New frmEmail(Date.Today)
Public Sub New frmEmail(ByVal reportDate As Date)
'....
End Sub
-
Jan 27th, 2012, 08:49 AM
#7
Thread Starter
Addicted Member
Re: Using Constructor Event Creates Errors...
Thanks, I tried that and it still made my screen flicker thought maybe I did something wrong.
Attempted it again, still flickered, but with a little modification, I set the form's DialogResult
OK (or Abort...if error reading db) so form wouldn't show
Cancel to show from but with the email data on screen to manually email it.
Thank you. This 4 hour headache is finally complete.
-
Jan 27th, 2012, 09:56 AM
#8
Hyperactive Member
Re: [RESOLVED] Using Constructor Event Creates Errors...
You should check if the form is double buffered and make sure it is "True"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|