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

NullReferenceException

Status
Not open for further replies.

proteome

Technical User
May 14, 2003
115
US
I have been getting the following error:

An unhandled exception of type 'System.NullReferenceException' occurred in Sample LogIn.exe

Additional information: The database could not be found!!

my code is below

Dim strSQL As String
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim tbd As DAO.TableDef
Dim qrd As DAO.QueryDef
Try
db = ws.OpenDatabase("C:\LogIn_Samples.mdb")
Catch f As NullReferenceException
Throw New NullReferenceException("The database could not be found!!", f)
End Try

Does anyone know how to remedy this error.
 
I don't use dao but could this help?

Code:
Dim ws As new DAO.Workspace

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I have recieved the same suggestion from another person but the problem is that workspace is an interface and you cannot use the term new there is a .WorkSpaceTypeEnum but I am unsure on how to use it.

Thanks
 
after A quick google I found this


and this code

Code:
Dim wrk As DAO.Workspace
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As QueryDef

[b]Set wrk = CreateWorkspace("", "Admin", "", dbUseJet)[/b]
'Change database path
Set db = wrk.OpenDatabase("D:Examplesdb1.mdb")
Set qdf = db.QueryDefs("qryParamQuery")

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks for your hard work but the above example doesn't seem to work either it seems as if you have to create a DAO.DBEngine and work from there see code below (by the way how do you get your code in the nice white box??)

Dim strSQL As String
Dim ws As DAO.Workspace
Dim Engine As New DAO.DBEngine()
Dim db As DAO.Database

ws = Engine.CreateWorkspace("", "Admin", "", )

Try
db = ws.OpenDatabase("C:\LogIn_Samples.mdb")
MsgBox("You have done it??")
Catch f As NullReferenceException
Throw New NullReferenceException("The database could not be found!!", f)
End Try

This works thanks again [thumbsup2]
 
for the nice white box

click on "process tgml" just above the "submit post" button.



Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top