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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SaveFileDialog breaking up

Status
Not open for further replies.

saadabc

Programmer
Aug 5, 2004
107
US

Hi - I have the following code to get a FileDialog box... the code is working in the development environment but when i build the solution and install it on another machine - it gives an error at the line

If .ShowDialog = DialogResult.OK Then


The error says 'Object reference not set to an instance of an object. Why is that - and how do i fix it ....







Friend WithEvents sfdRMSecurity As new System.Windows.Forms.SaveFileDialog

With sfdRMSecurity
.CheckPathExists = True
.Filter = "Excel files|*.xls"
.InitialDirectory = "c:" 'Environment.SpecialFolder.Personal
.OverwritePrompt = False

MsgBox("before Dialog shown")

If .ShowDialog = DialogResult.OK Then
MsgBox("after dialog shown")
saveName = .FileName

Else
Exit Sub
End If
End With


 
this is what I tried and it works just fine. where did you declare the sfdRMsecurity?

Code:
[Blue]Public[/Blue] [Blue]Class[/Blue] Form1
    [Blue]Friend[/Blue] WithEvents sfdRMSecurity [Blue]As[/Blue] [Blue]New[/Blue] System.Windows.Forms.SaveFileDialog

    [Blue]Public[/Blue] [Blue]Sub[/Blue] opensavedialog()
        [Blue]Dim[/Blue] savename [Blue]As[/Blue] [Blue]String[/Blue]

        With sfdRMSecurity
            .CheckPathExists = [Blue]True[/Blue]
            .Filter = [Red]"Excel files|*.xls"[/Red]
            .InitialDirectory = [Red]"c:"[/Red] [Green]'Environment.SpecialFolder.Personal[/Green]
            .OverwritePrompt = [Blue]False[/Blue]

            MsgBox([Red]"before Dialog shown"[/Red])

            [Blue]If[/Blue] .ShowDialog = System.Windows.Forms.DialogResult.OK [Blue]Then[/Blue]
                MsgBox([Red]"after dialog shown"[/Red])
                saveName = .FileName

            [Blue]Else[/Blue]
                [Blue]Exit[/Blue] [Blue]Sub[/Blue]
            [Blue]End[/Blue] [Blue]If[/Blue]
        [Blue]End[/Blue] With

    [Blue]End[/Blue] [Blue]Sub[/Blue]

    [Blue]Private[/Blue] [Blue]Sub[/Blue] Form1_Click([Blue]ByVal[/Blue] sender [Blue]As[/Blue] Object, [Blue]ByVal[/Blue] e [Blue]As[/Blue] System.EventArgs) [Blue]Handles[/Blue] [Blue]Me[/Blue].Click
        opensavedialog()
    [Blue]End[/Blue] [Blue]Sub[/Blue]
[Blue]End[/Blue] [Blue]Class[/Blue]

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 

sfdRMSecurity is declared by Form Designer in the Windows Form Designer declaration area. It is then initialized in the InitializeComponent() routine.

when i run the code in the development environment hitting F5... the dialog box appears... but then i run on a test machine - and it gives me that error message...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top