Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Sample Codes for SQL for Excel VBA


Hi, currently, I am using Excel 2000. I would like to do the below in VBA. I
am new in SQL Programming in VBA. To help you to understand myself better, I
have been programming in VBA for Excel quite sometimes. But for the below, I
am totally new.
Pls help me. It is urgent.

01) Check that a local pc connected to an SQL Server (This server is located
in my
office) successfully.
02) Connect to the SQL Server.
03) Open the database.
04) Open a table in this database.
05) Extract this table.
06) Copy all extracted records and paste in one worksheet in my Excel File.
07) Close the table.
08) Close the database.
09) Close the connection.

You may reply to my below email addresses.

01)
02)


Thanks and Best Regards
Sandra Poh
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Sample Codes for SQL for Excel VBA

Fortunately, you are not the first:

http://tinyurl.com/kac4o

--
Regards,
Tom Ogilvy


"Sandra Poh" wrote:


Hi, currently, I am using Excel 2000. I would like to do the below in VBA. I
am new in SQL Programming in VBA. To help you to understand myself better, I
have been programming in VBA for Excel quite sometimes. But for the below, I
am totally new.
Pls help me. It is urgent.

01) Check that a local pc connected to an SQL Server (This server is located
in my
office) successfully.
02) Connect to the SQL Server.
03) Open the database.
04) Open a table in this database.
05) Extract this table.
06) Copy all extracted records and paste in one worksheet in my Excel File.
07) Close the table.
08) Close the database.
09) Close the connection.

You may reply to my below email addresses.

01)
02)


Thanks and Best Regards
Sandra Poh

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Sample Codes for SQL for Excel VBA

Dear Tom,
Thanks. From your hyperlink, I have tried to go thru the thread and did a
sample code in the VBA of a new Excel workbook as shown below.


/////////Start of Code
Sub Test()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim shtCopy As Worksheet
Set shtCopy = ThisWorkbook.Worksheets("MOS Material Master")

'cn.Open "Provider=SQLOLEDB;Data Source=FRKfwd03;" & "Initial
Catalog=ORS2K;UID=SA;PWD=;"
'rs.Open "tbl1", conn, adOpenDynamic, adLockPessimistic

cn.Open "Provider=SQLOLEDB;Data Source=MOS;" & "Initial
Catalog=MOS;UID=sandra;PWD=;"
rs.Open "Product", conn, adOpenDynamic, adLockPessimistic

shtCopy.Activate
shtCopy.Range("A1").CopyFromRecordset rs

End Sub

End of Code////////////


Questions
======
01) When I tried to run the program, it ends with the the below error
message. I am
not sure which part of my code have when wrong. I have tried this when
running
the program in my office where the SQL server is.

Run-time error '-2147467259 (80004005);
Automation error
Unspecified error

02) As per the above source code, I am not sure of the below part. Pls
explain.
"Provider=SQLOLEDB;Data Source=MOS;" & "Initial
Catalog=MOS;UID=sandra;PWD=;"

I need guidance urgently.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Sample Codes for SQL for Excel VBA

Dear Tom,
Thanks. From your hyperlink, I have tried to go thru the thread and did a
sample code in the VBA of a new Excel workbook as shown below.


/////////Start of Code
Sub Test()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim shtCopy As Worksheet
Set shtCopy = ThisWorkbook.Worksheets("MOS Material Master")

'cn.Open "Provider=SQLOLEDB;Data Source=FRKfwd03;" & "Initial
Catalog=ORS2K;UID=SA;PWD=;"
'rs.Open "tbl1", conn, adOpenDynamic, adLockPessimistic

cn.Open "Provider=SQLOLEDB;Data Source=MOS;" & "Initial
Catalog=MOS;UID=sandra;PWD=;"
rs.Open "Product", conn, adOpenDynamic, adLockPessimistic

shtCopy.Activate
shtCopy.Range("A1").CopyFromRecordset rs

End Sub

End of Code////////////


Questions
======
01) When I tried to run the program, it ends with the the below error
message. I am
not sure which part of my code have when wrong. I have tried this when
running
the program in my office where the SQL server is.

Run-time error '-2147467259 (80004005);
Automation error
Unspecified error

02) As per the above source code, I am not sure of the below part. Pls
explain.
"Provider=SQLOLEDB;Data Source=MOS;" & "Initial
Catalog=MOS;UID=sandra;PWD=;"

I need guidance urgently.

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
SAMPLE EXCEL DATA EricB Excel Worksheet Functions 2 April 30th 10 03:44 PM
Can I random sample from a set until every sample is selected? random sampling Excel Discussion (Misc queries) 6 April 26th 10 09:54 PM
Sample Codes for SQL for Excel VBA Sandra Poh Excel Discussion (Misc queries) 1 May 16th 06 06:28 PM
is there any sample of an excel dashboard ? Gabe Excel Programming 3 November 8th 05 01:35 PM
Sample selection in Excel Gary's Student Excel Worksheet Functions 6 August 31st 05 05:30 PM


All times are GMT +1. The time now is 11:55 PM.

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"