I am just starting out with VBA 2005 and have written (copied) a routine from the "VB2005 in 24 Hrs" book, which will not run. The code is (I'm sure) written correctly but when the code tries to show the file dialog box (on clicking the SelectPicture" button), I get an error dialog box saying ""INVALIDOPERATIONEXCEPTION WAS UNHANDLED File<make empty> is not a valid name".
The code is listed below..... Can anyone see what I've done wrong?
Andy
Public Class frmViewer
Private Sub btnSelectPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectPicture.Click
'Show the open file dialogue box.
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
'Load the Picture into the Picture box.
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName)
'Show the name of the file in the form's caption.
Me.Text = "Picture Viewer(" & ofdSelectPicture.FileName & ")"
End If
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
'Close the window and exit the application
Me.Close()
End Sub
End Class
The code is listed below..... Can anyone see what I've done wrong?
Andy
Public Class frmViewer
Private Sub btnSelectPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectPicture.Click
'Show the open file dialogue box.
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
'Load the Picture into the Picture box.
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName)
'Show the name of the file in the form's caption.
Me.Text = "Picture Viewer(" & ofdSelectPicture.FileName & ")"
End If
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
'Close the window and exit the application
Me.Close()
End Sub
End Class