Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,670
Default How to connect to database?

I get an Access database named DBFiles with a table DBTable, and it has been
created through the ODBC connection named DBODBC. Within the DBTable, there
are 2 fields, Name and Phone as shown below.

Name Phone
Peter 1234
Mary 3456
John 5678

Does anyone have any suggestions on how to make a connection to table
DBTable and retrieve the data field into excel?
Thank for any suggestions
Eric
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default How to connect to database?


Sub GetData()
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary

sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "c:\DBFiles.mdb"

sSQL = "SELECT Name, Phone From DBTable"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText

' Check to make sure we received data.
If Not oRS.EOF Then
ary = oRS.getrows
MsgBox ary(0, 0) & " " & ary(1, 0)
Else
MsgBox "No records returned.", vbCritical
End If

oRS.Close
Set oRS = Nothing
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Eric" wrote in message
...
I get an Access database named DBFiles with a table DBTable, and it has
been
created through the ODBC connection named DBODBC. Within the DBTable,
there
are 2 fields, Name and Phone as shown below.

Name Phone
Peter 1234
Mary 3456
John 5678

Does anyone have any suggestions on how to make a connection to table
DBTable and retrieve the data field into excel?
Thank for any suggestions
Eric



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,670
Default How to connect to database?

Thank you for your suggestions
Could you please tell me how to get all the value into the cells rather than
display in MsgBox?
Thank for any suggestions
Eric

"Bob Phillips" wrote:


Sub GetData()
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary

sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "c:\DBFiles.mdb"

sSQL = "SELECT Name, Phone From DBTable"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText

' Check to make sure we received data.
If Not oRS.EOF Then
ary = oRS.getrows
MsgBox ary(0, 0) & " " & ary(1, 0)
Else
MsgBox "No records returned.", vbCritical
End If

oRS.Close
Set oRS = Nothing
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Eric" wrote in message
...
I get an Access database named DBFiles with a table DBTable, and it has
been
created through the ODBC connection named DBODBC. Within the DBTable,
there
are 2 fields, Name and Phone as shown below.

Name Phone
Peter 1234
Mary 3456
John 5678

Does anyone have any suggestions on how to make a connection to table
DBTable and retrieve the data field into excel?
Thank for any suggestions
Eric




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default How to connect to database?

GetRows creates an array. Just drop that array in a range, or loop through
it. My example just MsgBox's one or two elements to show it works.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Eric" wrote in message
...
Thank you for your suggestions
Could you please tell me how to get all the value into the cells rather
than
display in MsgBox?
Thank for any suggestions
Eric

"Bob Phillips" wrote:


Sub GetData()
Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary

sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "c:\DBFiles.mdb"

sSQL = "SELECT Name, Phone From DBTable"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText

' Check to make sure we received data.
If Not oRS.EOF Then
ary = oRS.getrows
MsgBox ary(0, 0) & " " & ary(1, 0)
Else
MsgBox "No records returned.", vbCritical
End If

oRS.Close
Set oRS = Nothing
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Eric" wrote in message
...
I get an Access database named DBFiles with a table DBTable, and it has
been
created through the ODBC connection named DBODBC. Within the DBTable,
there
are 2 fields, Name and Phone as shown below.

Name Phone
Peter 1234
Mary 3456
John 5678

Does anyone have any suggestions on how to make a connection to table
DBTable and retrieve the data field into excel?
Thank for any suggestions
Eric






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect Excel to stored procedures in SQL database? tskogstrom Excel Discussion (Misc queries) 1 July 3rd 07 09:40 AM
How to connect Excel to stored procedures in SQL database? tskogstrom Excel Discussion (Misc queries) 1 July 2nd 07 03:56 PM
connect to access database and run a query in excel VBA Bob Excel Discussion (Misc queries) 0 April 25th 06 08:12 PM
connect a form to excel database Kathy Excel Discussion (Misc queries) 5 October 10th 05 06:17 AM
i want to connect excel with sql server 2000 as database with macr khurram saddique Excel Discussion (Misc queries) 2 February 18th 05 11:09 AM


All times are GMT +1. The time now is 11:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"