I am not sure what I am doing wrong, but here it goes.
Recently I downloaded a trial version of a control called Active Query Builder. I looked at one project called GeneralDemo.vbproj and started looking at its structure.
It contained a nice visual basic program to start the application, so I reused it.
Imports System.Threading
Imports System.Windows.Forms
Friend NotInheritable Class Start
Private Sub New()
End Sub
<STAThread> _
Friend Shared Sub Main()
AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf CurrentDomain_UnhandledException
AddHandler Application.ThreadException, _
AddressOf Thread_UnhandledException
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New AccessConnectionForm())
End Sub
Private Shared Sub CurrentDomain_UnhandledException(sender As Object, _
e As UnhandledExceptionEventArgs)
Dim exception As Exception = TryCast(e.ExceptionObject, Exception)
If exception IsNot Nothing Then
Dim exceptionDialog As New ThreadExceptionDialog(exception)
If exceptionDialog.ShowDialog() = DialogResult.Abort Then
Application.[Exit]()
End If
End If
End Sub
Private Shared Sub Thread_UnhandledException(sender As Object, _
e As ThreadExceptionEventArgs)
If e.Exception IsNot Nothing Then
Dim exceptionDialog As New ThreadExceptionDialog(e.Exception)
If exceptionDialog.ShowDialog() = DialogResult.Abort Then
Application.[Exit]()
End If
End If
End Sub
End Class
The demo program also contained different connection forms for different database systems. For fun, I wanted to place an image to show me to which database I was trying to connect. So I placed a picture box on the form and I TRIED to load the .PNG file into the picture box.
Imports System.Data.OleDb
Imports System.Windows.Forms
Partial Public Class AccessConnectionForm
Inherits Form
Public strAppPAth As String = Application.StartupPath
Public ConnectionString As String = ""
Public Sub New()
InitializeComponent()
picDB.Image = Image.FromFile(strAppPAth & "MS-Access.png")
End Sub
Private Sub btnConnect_Click(sender As Object, _
e As EventArgs) Handles btnConnect.Click
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0"
ConnectionString += ";Data Source=" & txtDB.Text
ConnectionString += ";User Id=" & txtDB.Text
ConnectionString += ";Password="
If txtDB.Text.Length > 0 Then
ConnectionString += txtDB.Text & ";"
End If
Using connection As New OleDbConnection(ConnectionString)
Me.Cursor = Cursors.WaitCursor
Try
connection.Open()
Catch ex As System.Exception
MessageBox.Show(ex.Message, "Connection Failure.")
Me.DialogResult = DialogResult.None
Finally
Me.Cursor = Cursors.[Default]
End Try
End Using
End Sub
Private Sub btnBrowse_Click(sender As Object, _
e As EventArgs) Handles btnBrowse.Click
If openFileDialog1.ShowDialog() = DialogResult.OK Then
txtDB.Text = openFileDialog1.FileName
End If
End Sub
End Class
I get an error at the strAppPath variable. I am trying to make the program executable from anywhere and it does not recognize the Resources folder where I am currently storing the image.
What I have tried:
The only thing I added was:
Public strAppPath As String = Application.StartupPath
At the top of the Access Connection form. and -
picDB.Image = Image.FromFile(strAppPAth & "MS-Access.png")
In the Public Sub New procedure when the form is started.
Can some one point out what I did wrong?
Thank you,