1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

VB connection to access

Discussion in 'Software Q&A' started by deepak.krishnan, Mar 18, 2006.

Thread Status:
Not open for further replies.
  1. deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    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.
     
  2. RCuber

    RCuber The Mighty Unkel!!! Staff Member

    Joined:
    Sep 7, 2004
    Messages:
    7,105
    Likes Received:
    12
    Trophy Points:
    38
    Location:
    ಬೆಂಗಳೂರು (Bengaluru)
    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.
     
  3. OP
    OP
    deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    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.
     
  4. RCuber

    RCuber The Mighty Unkel!!! Staff Member

    Joined:
    Sep 7, 2004
    Messages:
    7,105
    Likes Received:
    12
    Trophy Points:
    38
    Location:
    ಬೆಂಗಳೂರು (Bengaluru)
    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
     
  5. ~Phenom~

    ~Phenom~ The No.1 Stupid

    Joined:
    May 17, 2005
    Messages:
    1,703
    Likes Received:
    5
    Trophy Points:
    0
    Location:
    CYBERYARD
    Although even I had learnt VB more than a year ago, I think charangk's solution should work.
     
  6. it_waaznt_me

    it_waaznt_me Coming back to life ..

    Joined:
    Nov 30, 2003
    Messages:
    2,023
    Likes Received:
    10
    Trophy Points:
    38
    Location:
    A bit closer to heaven
    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.
     
  7. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    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
     
  8. OP
    OP
    deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    How can I give relative path?
     
  9. it_waaznt_me

    it_waaznt_me Coming back to life ..

    Joined:
    Nov 30, 2003
    Messages:
    2,023
    Likes Received:
    10
    Trophy Points:
    38
    Location:
    A bit closer to heaven
    Our variable strPath is the relative path to the program location.
     
  10. nikdesign4u

    nikdesign4u New Member

    Joined:
    Nov 9, 2005
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Thane
    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
     
  11. PainKiller

    PainKiller thug for life...2pac

    Joined:
    Jul 29, 2005
    Messages:
    182
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    nEw dElHi [wEsT]
    most of the answers r correct...ur program shud work fine :)
     
  12. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    :x There was no need of a confirmation to the authenticity of our answers!! :x
     
  13. OP
    OP
    deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    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?)
     
  14. OP
    OP
    deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    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.
     
  15. it_waaznt_me

    it_waaznt_me Coming back to life ..

    Joined:
    Nov 30, 2003
    Messages:
    2,023
    Likes Received:
    10
    Trophy Points:
    38
    Location:
    A bit closer to heaven
    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" 
    
    
     
  16. OP
    OP
    deepak.krishnan

    deepak.krishnan New Member

    Joined:
    Jan 11, 2005
    Messages:
    423
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Palakkad/Bangalore
    im using ADO.How can I give a elative path in the data property
     
Thread Status:
Not open for further replies.

Share This Page