Results 1 to 14 of 14

Thread: automatic detect and bind a Link to .mdb

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    Thumbs down automatic detect and bind a Link to .mdb

    1.) Does anyone know how make an executable program (.exe)
    that has the capability to automatically detect a database
    regardless of where the database is located in the harddisk?


    (E.g. Everytime the (.exe ) program is executed, it will first locate for a database called cust.mdb and bind a link to it then only subsequently run the rest of the program.)
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    You would have to have your program do a recursive folder search across your hard drive until it found a match, load the path into a variable, and then feed that variable into your connect string.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    Example please

    I know what it means but could comeone give me an example of coding them? (cause i am still fresh in this )
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275

    Wink

    I will pass you the code:

    VB CODE ------------

    Option Explicit

    Private Declare Function SearchTreeForFile Lib "imagehlp" _
    (ByVal RootPath As String, ByVal InputPathName As String, _
    ByVal OutputPathBuffer As String) As Long

    Private Const MAX_PATH = 260

    Public Function ZoekBestand(Station As String, Bestand As String) As String

    Dim tempStr As String
    Dim Ret As Long

    tempStr = String(MAX_PATH, 0)

    Ret = SearchTreeForFile(Station, Bestand, tempStr)
    If Ret <> 0 Then
    ZoekBestand = Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
    Else
    ZoekBestand = ""
    End If

    End Function

    END CODE --------------

    Place this code in a module.

    Call the function with as first argument the drive letter where you want to search at, second argument the filename.

    Greetz, Luc

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    Trying them out

    Thanks for the code and i will try them first.
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    Still doubt!!! : (

    Ohh !! HELP PLEASE

    I think it is working but one stupid thing i still doubt about that.

    Can you or anyone explain the above to me (briefly) ? (to better understand)

    does it means that after i execute that, i don't need to use an icon called data(to link to the database anymore)?

    If so then what am i suppose to do to call a particular table from that database for amendment. currently, i am using the technique shown below. (note : its just part of my code)

    customer.recordset.movefirst
    customer.recordset.edit
    customer.recordset.fields("custname").value = text1.text
    customer.recordset.update
    Last edited by secretgenius1; Sep 22nd, 2001 at 09:46 AM.
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  7. #7
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    I do not know what you mean with 'an icon called data' but what you need to do is find the path to the database, pass this thru to your connectionstring and therewith open your database.
    In this case you make the connection to the database with code, not thru an control.

    If you have more questions about it, let me know.

    Luc

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    Can anyone show me how it is done?

    Luc !!!

    can you show me in coding so that i can better understand them? cause i almost crack my head trying to figure them out.

    or does anyone has any idea just shown me how it is done.
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  9. #9
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    You have to make a reference to ADO via 'Project/References/Microsoft Activex Data Objects 2.1 Library' (or higher)

    Now, i named the Searchmodule 'modZoek' and placed a form with a commandbutton and a textfield.

    After the form, place following code:

    Begin Code ----

    Option Explicit

    Private cn As ADODB.Connection
    Private rs As ADODB.Recordset
    Private Path As String

    Private Sub Command1_Click()

    'You may have to change the Jet.OLEDB provider in the connectionstring
    ', 3.51 is for Acces97, 4.0 for Acces2000

    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    'This is the way to do it when you know the path.
    'cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
    'Now we use the module to search the path
    Path = modZoek.ZoekBestand("C:\", "Biblio.mdb")
    If Path = "" Then
    MsgBox "DB not found!"
    Exit Sub
    End If
    cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & Path

    rs.CursorType = adOpenDynamic
    rs.ActiveConnection = cn
    rs.Source = "SELECT * FROM Authors;"
    rs.Open
    'Set rs = cn.Execute("SELECT * FROM Authors;")

    While Not rs.EOF
    Me.Text1.Text = rs.Fields(1).Value '= Second field, 0 is first field
    If MsgBox("Next?", vbYesNo) = vbNo Then
    rs.MoveLast
    End If
    rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    End Sub

    EndCode ----

    Tip: to build the connectionstring, use the Microsoft ADO Data control (Project/Components), and copy-paste the connectionstring in your code.

    Hope this helps.
    Greetz, Luc

  10. #10
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    At which line do you get the error? if it's difficult to say, post me the project (or a part of it) so i can take a look at it.

    Greetz, Luc

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    OKKK

    Option Explicit

    Private cn As ADODB.Connection
    Private rs As ADODB.Recordset
    Private Path As String

    Private Sub Command1_Click()

    'You may have to change the Jet.OLEDB provider in the connectionstring
    ', 3.51 is for Acces97, 4.0 for Acces2000

    Set cn = New ADODB.Connection ======= this line is highlighted
    Set rs = New ADODB.Recordset


    Buddy the line above indicate the highlighted part when that error pop up

    or may want to view at the zip file
    Attached Files Attached Files
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  12. #12
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    This is an error that i don't get, it's more something that lays by your configuration i think. Try referencing to the ADO activex data objects 2.1, instead of referencing to 2.5 and 2.6 and multidimensional at the same time.
    This seems like a ado version conflict bug.
    if above solution does not help, try downloading mdac 2.6 from the microsoft web site (www.microsoft.com/data ), this may solve your problem.

    Let me know if it doesn't help.

    Luc,

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Malaysia
    Posts
    176

    I sEEEE

    Thanks buddy , your code is working .

    Actually its my computer problem . i do not know how to tackle this.

    When i reinstall all the Visual studio stuff, all the *.dll files cannot register in the system registry.


    Current OS = Windows Mellinium

    can anyone tell me how to deal with this?
    Tell me the TRUTH of the TRUTH, Nothing but the TRUTH,
    Thank You!

  14. #14
    Junior Member
    Join Date
    Aug 1999
    Location
    Bombay,Maharashtra,India
    Posts
    20
    Luc...yr code was excellent...can u please tell me what does the library file do...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width