I am using an Access Database through Visual Basic 6.
Is there any other way to access the database excluding the following code.

Set CNN = New ADODB.Connection
str = "\\SYS8\DATAX\EMP.MDB"
CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + str + ";Persist Security Info=False"
CNN.CursorLocation = adUseClient

I'm not sure why you don't like the code you have if it works, but just in case you're interested, this is the way I ususally do it:


Dim wrkJet As Workspace
Dim dbProgram As Database
Dim wOrders As Recordset
Set wrkJet = CreateWorkspace("", "Admin", "", dbUseJet)
Set dbProgram = wrkJet.OpenDatabase("myDBName.mdb")
Set wOrders = dbProgram.OpenRecordset("SELECT * FROM Orders ORDER BY OrderNumber", dbOpenSnapshot)
.
.
.

Thanks.

but here also

Dim wrkJet As Workspace
Dim dbProgram As Database
Dim wOrders As Recordset
Set wrkJet = CreateWorkspace("", "Admin", "", dbUseJet)
Set dbProgram = wrkJet.OpenDatabase("myDBName.mdb")
Set wOrders = dbProgram.OpenRecordset("SELECT * FROM Orders ORDER BY OrderNumber", dbOpenSnapshot)

we have to give the path.
Actually I have done my work using the above one but
I just want to know is there any method or technique to use MS Access DB without using Path.

Where do you want to get the name of the database from? The choices are to hard code it, (not your favorite obviously), to pass it as a parameter to the application via the command line (not my favorite approach), to store it in a parameter file, the name of which can be specified on the command line used to open the application (my favorite approach), to create a form that asks the user to enter it. Maybe you can think of some other ways as well.

Name your poison,

Hoppy

I put the path in my main sub of main module and call it strdb.
In the code I always write
CNN.open strdb
this way when there is a change you change it in the module and not every time you used the connection string

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.