This is Dana Wyatt from Hands On Technology Transfer. Here are some thoughts I have:
1) I concur that your connection object needs to be LOCAL to the method. When you reference a public variable in another form, it may be null if the form doesn't exist.
Public Shared Function SqlScalar(ByVal sql As String) As Object
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= G:\mypath\mydatabase.accdb")
Dim cmd As New OleDbCommand(sql, frmMain.con)
con.Open()
Dim Scalar As Object = cmd.ExecuteScalar
con.Close()
Return Scalar
End Function
2) Somewhere along VS 2010, it quit throwing exceptions when a connection string is partly wrong. So you can have an open that doesn't work and not fail until later in the method. SO MAKE ABSOLUTELY SURE your connection string is 100% right. It would be best to put it in the section of a config file and ALWAYS load it from there.
3) Finally, the buggy behavior on one machine but not another leads me to believe you have a driver issue on one or more machines for the accdb databases. Make sure you have the latest Office System Drivers, engines, etc downloaded.
http://www.microsoft.com/en-us/download/details.aspx?id=13255
Try all of this. Let us know at HOTT if this works. I believe you are e-mailing Chris E. And if it doesn't work, we will try to think of more issues.
Personally, I believe it isn't ONE problem, but a combinaion of several... kinda like three bad wheels on a grocery buggy!!! : )
-Dana