Solved

open Database connection on excel vba example

Posted on 2010-08-23
3
772 Views
Last Modified: 2012-05-10
Hi,
I need help to guide me how could I open connection, recordset from excel vba
what I looking is ODBC connection with recordset and paste records on excel cells....
That's !
Thank you!
0
Comment
Question by:fsze88
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
MSmax earned 500 total points
Comment Utility
hi, try below code:
Dim cnn As ADODB.Connection

Dim rst As ADODB.Recordset



Set cnn = New ADODB.Connection

Set rst = New ADODB.Recordset



cnn.Open "YourDSN", "YourUsername", "YourPassword"

rst.ActiveConnection = cnn

rst.CursorLocation = adUseServer



rst.Source = "SELECT * FROM TABLE WHERE FIELD='data'"

rst.Open

variable = rst.Fields("FIELD") ' Do whatever you need to the data

rst.Close



Set rst = Nothing

Set cnn = Nothing

Open in new window

0
 
LVL 15

Author Comment

by:fsze88
Comment Utility
hi, thank you

but It said User-defined type not defined.

Could you help?
Untitled.png
0
 
LVL 7

Assisted Solution

by:MSmax
MSmax earned 500 total points
Comment Utility
That's because you haven't got references to ADO libraries.
To add them go to VBA Editor-Tools-References and chose Microsoft ActiveX Data Objects 2.x Library
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now