listbox refresh problem

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
Hi,
Im running in the following issue which I cant get solved.

I have two forms.
when I click the savebutton a second form popsup and asks for the file name to save.
this works fine.
now when the user hits the savebutton. I want a listbox the be refreshed (this contains all files in a directory) on form one and close the second(save) form.

this is what i have
form one (frmSetup)
VB.NET:
Expand Collapse Copy
[COLOR=#0000ff]Private[/COLOR][COLOR=#0000ff]Sub[/COLOR] SaveEmail()
[COLOR=#008000]' strTemplateText = Me.txtTemplateText.Text
[/COLOR][COLOR=#0000ff]If[/COLOR] blAdd [COLOR=#0000ff]Then
[/COLOR][COLOR=#0000ff]Dim[/COLOR] SaveForm [COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]New[/COLOR] frmSave
SaveForm.Show()
[COLOR=#0000ff]Else
[/COLOR][COLOR=#0000ff]Dim[/COLOR] strFileName [COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]String[/COLOR] = ""
SaveEmailTemplate(glstrEmailTemplateName, [COLOR=#0000ff]Me[/COLOR].txtTemplateText.Text)
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]If
[/COLOR]

on form two (frmSave)
VB.NET:
Expand Collapse Copy
[COLOR=#0000ff]
Private[/COLOR][COLOR=#0000ff]Sub[/COLOR] btnSave_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] btnSave.Click
 
SaveEmailTemplate(glstrEmailTemplateName, glstrEmailtemplateContent)
formSetup.EmailtabInit()
[COLOR=#008000]'finally
[/COLOR][COLOR=#0000ff]Me[/COLOR].Close()

emailTabinit is the routine (located on form one) which reads the files.
I referenced form two(frmSave) on form one(frmSetup)
VB.NET:
Expand Collapse Copy
[COLOR=#0000ff]
Friend[/COLOR][COLOR=#0000ff]WithEvents[/COLOR] FormSave [COLOR=#0000ff]As[/COLOR] dbaccess.frmSave
and form one (frmSetup) on form two (frmSave)
VB.NET:
Expand Collapse Copy
[COLOR=#0000ff]Friend[/COLOR][COLOR=#0000ff]WithEvents[/COLOR] formSetup [COLOR=#0000ff]As[/COLOR] dbaccess.frmSetup

the error message, I get at formSetup.EmailtabInit() is:
Object reference not set to an instance of an object.

does this make sense to anyone?

help is appreciated
thanks in advance
 
It means that the formSetup variable does not refer to an object. The usual reason for this is because you have declared the variable but never create an object using the "New" keyword.
 
hi jmcilhinny

thx for your reply. that does make sense. But where do I create the "New" object of this form?

I've never had to use this, thus I'm not familiar with this, yet

when i declare Code:
Dim formsave AsNew frmsave

it says that this is already declared as friend withevents

can you give me some more information

thanks
 
You don't declare another variable. You assign a new object to the existing variable, e.g.
VB.NET:
Expand Collapse Copy
Private myObject As Object 'The variable is declared.

myObject = New Object 'The object is created and assigned to the variable.
Note that there can be as much code as you like between those two lines.
 
thx

sorry for my (stupid) questions but its not clear to me yet. Like i said this is new to me.

when i declare private frmSetup as object (just below
Windows Form Designer generated code)

Private frmSave As Object 'The variable is declared

where do i put
frmSave = New Object 'The object is created and assigned to the variable.

at the end of sub PrivateSub SaveEmail()???
(as you see, i dont understand, the method
I assume that I have to make the decl in the frmSetup (form one)

can you be more specific to my case?

thx
 
alaric said:
when i declare Code:
Dim formsave AsNew frmsave

it says that this is already declared as friend withevents
this is where you change the problem line to:
VB.NET:
Expand Collapse Copy
formsave =New frmsave
 
Back
Top