|
-
Oct 2nd, 2000, 02:42 PM
#1
Thread Starter
Member
Is there a way in Vb to call a query from an Access database?
-
Oct 2nd, 2000, 03:00 PM
#2
Absolutely, take your pick at what object library you're going to use(ADO, RDO, DAO) and go ahead. I would suggest using ADO, since according to Microsoft, ADO is going to be the ultimate data access library (until they'll have something better).
Add a reference to Microsoft ActiveX Data Objects and do something like this (I assume that you query is meant to bring a recordset back i.e. it is a Select statement):
Code:
Dim cn As New ADODB.Connection
Dim cm As New ADODB.Command
Dim rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDatabase.mdb"
With cm
Set .ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "YourQueryName"
'If you have parameter(s) then you have to do something like this
'In this example I'm passing an Integer type parameter with value of 5
.Parameters.Append .CreateParameter("ParamName", adInteger, adParamInput, , 5)
Set rs = cm.Execute
End With
If Not rs.EOF Then
'Do your stuff with recordset here
End If
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Regards,
-
Oct 2nd, 2000, 03:03 PM
#3
Frenzied Member
You can also do it by opening an instance of Access, if Serge hasn't given you an approach you like...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|