DIGIT-ARC read-only archive · snapshot: July 23, 2026

VB connection to access

16 posts · originally from https://geek.digit.in/community/threads/vb-connection-to-access.25645/

deepak.krishnan
deepak.krishnan Original post #1
Mar 18, 2006 at 4:31 PM
Hello friends
I made a project in which I have to connect the concerned file to a database. But when I transferred it a CD and tried to work with it in another computer, I got the message saying that the database was not found in the spcified drive.The projesct was converted to *.exe in VB itself.Is there any way to code the program to connect to the database by searching the computer and finding out where it is located.Please help urgently.
RCuber
RCuber #2
Mar 18, 2006 at 4:37 PM
How do you access the database? and Where is the database stored? and also give the string which connects the program to the database then i could help.
deepak.krishnan
Mar 18, 2006 at 4:57 PM
well I made the database using the option in VB and the database is stored in:
f:\School Projects\open\idpro.mdb

idpro.mdb is the database name

There is a program which can store the information your want in the database.
RCuber
RCuber #4
Mar 18, 2006 at 8:39 PM
In the program find the string locating the database . If the path is as u said "f:\School Projects\open\idpro.mdb" then change it to "\open\idpro.mdb" and make sure the file is in that directory.. What this does is irrespective of the drive the software is installed the program looks for the file in "\open" directory. Take for example

the directory is some thing like this when u install the software.

d:\School Project --> the application directory of ur project where your exe file is there.

make another directory "open"

so that it looks like this
d:\School Project\open --> this is where the database will be stored locally.


and now do what i said in the code . This must work.

Its been more that three years since i last programmed in VB . I hope this thing works. Test it and let me know.
Charan
~Phenom~
Mar 18, 2006 at 11:27 PM
Although even I had learnt VB more than a year ago, I think charangk's solution should work.
it_waaznt_me
Mar 18, 2006 at 11:39 PM
Creeate string called strPath and Database location

Code:
Dim strPath as String
Dim strDatabaseLocation as String
strPath = App.Path
strDatabaseLocation = strPath & "\idpro.mdb"

Now use strDatabaseLocation in the connection string for your database object.
tuxfan
tuxfan #7
Mar 20, 2006 at 1:39 PM
What it_waaznt_me suggested will work if the .exe and the .mdb are in the same location (app.path). Actually, thats surely is the most advisable way to store the database.

Never give an absolute path in your code (like "C:\Program Files\MyApp\mydb.mdb"). If the software is installed in some other location, it won't work. So give a relative path and use app.path
it_waaznt_me
Mar 20, 2006 at 5:28 PM
Our variable strPath is the relative path to the program location.
N
Mar 20, 2006 at 7:53 PM
try following...

Dim AdoFa As New ADODB.Connection

Dim ConnectString As String

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb ; Persist Security Info=False"

With AdoFa
.ConnectionString = ConnectString
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.Open
End With
PainKiller
Mar 23, 2006 at 1:44 PM
most of the answers r correct...ur program shud work fine :)
tuxfan
tuxfan #12
Mar 23, 2006 at 2:09 PM
PainKiller said:
most of the answers r correct...ur program shud work fine :)

:x There was no need of a confirmation to the authenticity of our answers!! :x
deepak.krishnan
Mar 23, 2006 at 3:07 PM
nikdesign4u said:
try following...

Dim AdoFa As New ADODB.Connection

Dim ConnectString As String

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb ; Persist Security Info=False"

With AdoFa
.ConnectionString = ConnectString
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.Open
End With

I tried it by copying it into the code window of data object.But still the error appears that idpro.mdb could not be found.Where should I use the above code provided.(should it be in the code window of data object itself?)
deepak.krishnan
Mar 23, 2006 at 3:12 PM
it_waaznt_me said:
Creeate string called strPath and Database location

Code:
Dim strPath as String
Dim strDatabaseLocation as String
strPath = App.Path
strDatabaseLocation = strPath & "\idpro.mdb"

Now use strDatabaseLocation in the connection string for your database object.

I did not understand your code.Can you please elaborate that to me.I pasted your code in the general declerations window.But it dosent work.
An error appears saying that: "invalid outside procedure" and it highlights that App.path in your code.
it_waaznt_me
Mar 23, 2006 at 5:11 PM
Hmm.. First tell me how do you access the database ...? Are you using ADO ? or are you using code based as nikdesign suggested.

Waise nikdesign's method should work. Only change the :
Code:
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb Persist Security Info=False" 

to

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\idpro.mdb Persist Security Info=False"
deepak.krishnan
Mar 24, 2006 at 12:43 PM
im using ADO.How can I give a elative path in the data property