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!
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.
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.
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)
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.
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.
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.