Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Data Access

Status
Not open for further replies.

mans

Programmer
Mar 18, 2000
136
0
0
AU
Hello,<br><br>I have an Access2000 database that is secured by a one username and a password.&nbsp;&nbsp;I am using both DAO and ADO data access objects to access this database in one VB6 application.&nbsp;&nbsp;I have no problem writing code to allow the DAO access facility to access the secured database.&nbsp;&nbsp;I have spent many frustrating hours attempting to get the ADO object to do the same thing, can some one please let me know what I should do to resolve this issue, possibly with the help of some sample code if it is not too much trouble.<br><br>Regards
 
Here is some code that uses ADO to access an MS Access table.&nbsp;&nbsp;I hope you can get something from this code.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;' ado code for UPC table connection<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim strSQL As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim cnnConnection As ADODB.Connection<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim rstUPC As ADODB.Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set cnnConnection = New Connection<br>&nbsp;&nbsp;&nbsp;&nbsp;strSQL = &quot;select * from tblUPC&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;cnnConnection.ConnectionString = itsConnectionString<br>&nbsp;&nbsp;&nbsp;&nbsp;cnnConnection.Open<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rstUPC = GetRecordset(cnnConnection, strSQL)<br><br>and in a module I have:<br><br>Public Function GetRecordset(cnnConnection As ADODB.Connection, strQry As String) As ADODB.Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim rstUPC As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rstUPC = New Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;rstUPC.CursorType = adOpenKeyset<br>&nbsp;&nbsp;&nbsp;&nbsp;rstUPC.LockType = adLockOptimistic<br>&nbsp;&nbsp;&nbsp;&nbsp;rstUPC.CursorLocation = adUseClient<br>&nbsp;&nbsp;&nbsp;&nbsp;rstUPC.Source = strQry<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rstUPC.ActiveConnection = cnnConnection<br>&nbsp;&nbsp;&nbsp;&nbsp;rstUPC.Open<br>&nbsp;&nbsp;&nbsp;&nbsp;Set GetRecordset = rstUPC<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Function<br><br>I learned this from the Waite Group's Visual Basic 6 Superbible.&nbsp;&nbsp;It is an excellent book.<br> <p>Wally Wojciechowski<br><a href=mailto:wwojo@wilsonpet.com>wwojo@wilsonpet.com</a><br><a href= > </a><br>
 
Well, wallyw has it, but I'm gonna post some code to just because I'm bored...<br>-----------------------------------------------<br><br>dim db as new adodb.database<br>dim rs as new adodb.recordset<br>dim sql as string<br><br>db.Open &quot;driver=Microsoft Access Driver (*.mdb); dbq=&quot; & App.path & &quot;\databasename.mdb&quot;<br><br>sql = &quot;select * from tablename&quot;<br><br>rs.Open sql, db, adOpenKeyset, adLockPessimistic<br><br>-----------------------------------------------------------<br>Note that the &quot;db.open&quot; line is all one line, including app.path beneath it.<br><br>After that you can use the rs object as like a pretty much like dao through code (i.e. movenext, movefirst, movelast, delete, addnew, etc...).<br><br>HTH
 
If the problem is you cant open the connection to a password protected database, make sure you add the database password argument to the connection string.<br><br>DIM ADODBConnection as ADODB.Connection<br>DIM rs as ADODB.Recordset<br>DIM sSQL as String&nbsp;&nbsp;<br><br>SET ADODBConnection = New ADODB.Connection<br>Set rs = New ADODB.Recordset&nbsp;&nbsp;<br><br>sSQL = &quot; Select * FROM Tablename&quot;<br>&nbsp;&nbsp;&nbsp;ADODBConnection.Open &quot;PROVIDER=Microsoft.Jet.OLEDB.3.51;&quot; & _&quot;DATA SOURCE=&quot; & App.Path & &quot;\databasename.mdb&quot; & &quot;;&quot; & _<br>&quot;Jet OLEDB:Database Password=&quot; & &quot;yourDatabasePassword&quot;<br><br><br>rs.Open sSQL,ADODBConnection,adOpenKeyset,AdLockREadOnly,AdCmdText<br><br><br>with rs<br>' Do Whatever<br>end with<br><br>Set rs = nothing<br>Set ADODBConnection = nothing<br><br>Hope this helps<br>Stay Lucky<br>Will<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top