Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Retreiving Data from access

  Asked By: Hisham    Date: Sep 23    Category: MS Office    Views: 503
  

I am trying to access a database(testing.mdb) using VBA.There is a Marks tale
in that database whcih has several columns in it and Name is one of them.I am
trying to write a query to access all the names in that table and write it down
on the excel sheet.I came up with the following code.I did all the referencing
stuff.But when I am trying to run it it is not doing anything not even giving
any error.

Public gcnAccess As ADODB.Connection
Sub OpenAccessConnection()
Dim sConnect As String
Dim sSQL As String
Dim rsData As ADODB.Recordset
Dim sPath As String

sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\testing.mdb;"
Set gcnAccess = New ADODB.Connection
gcnAccess.ConnectionString = sConnect
gcnAccess.Open

sSQL = "SELECT Name " & _
"FROM Marks;"

Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, _
adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsData.EOF Then
Sheet1.Range("A1").CopyFromRecordset rsData
Else
MsgBox "No data located.", vbCritical, "Error!"
End If
rsData.Close
Set rsData = Nothing

gcnAccess.Close
End Sub

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Retreiving Data from access Or get search suggestion and latest updates.




Tagged: