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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 and MS Access

Status
Not open for further replies.

ChrisQuick

Programmer
Oct 4, 1999
144
US
I am trying to write an application that will connect to a MS Access database, create a recordset by running a SQL query, and then recursively read all the records returned to set some variables to be used elsewhere.<br>
<br>
I've gotten as far as:<br>
<br>
Dim cnnDbs As Database<br>
Dim strQuery As String<br>
Dim strFileName As String<br>
Dim strDesc As String<br>
cnnDbs = OpenDatabase(my.mdb&quot;)<br>
strQuery = (&quot;Select filename, description from fileListTable where username = 'Bob'&quot;)<br>
<br>
But I don't know how to pass the query to the connection make the recordset. Any help?<br>
<br>

 
Chris,<br>
<br>
I have a Global module that I set up an use all the time when I am writing. It looks something like<br>
<br>
Function sql_call(sSQL As Variant) As Recordset<br>
<br>
On Error GoTo trap<br>
Dim error_num As Long<br>
Dim error_desc As String<br>
Dim RECORD_SET As Recordset<br>
Dim et As String<br>
<br>
Set RECORD_SET = LocDB.OpenRecordset(sSQL)<br>
Set sql_call = RECORD_SET<br>
<br>
trap:...etc<br>
<br>
Exit Function<br>
<br>
Where LocDB is my database that I have set up globally so that I can refer to in in all of my forms etc. If I come across a point where I need to create a record set I can simply create my sql string (as you are doing and in the next line say:<br>
sql_call (ssql)<br>
<br>
I hope this helps<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top