Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default Anyone going from MySql on web server to Excel on desktop?

Is anyone doing VBA/Excel to MySql stuff? Perhaps with Microsoft
ActiveX DataObjects 2.5 Library (msado15.dll).

Could use some help / simple sample code.

As of about three weeks ago am doing multiple table joins off of
Excel Spreadsheets (all local). VERY COOL! Some simple code below
thanks to (and adapted from) Osgrid.

This is a key part of a larger project. See http://www.ITSDoc.org for
more info.

Rick



sub mySQL1()
'use SQL with Excel tables as input, Excel table as output
'need a ref to Microsoft ActiveX DataObjects 2.5 Library (msado15.dll)
'http://www.ozgrid.com/forum/showthread.php?t=25076

'To attach to tables use any of the following:
' WorkSheet "Select * from [Sheet1$]" (entire used range returned)
' Ranges "Select * from [Sheet1$A1:B10]"
' Named Ranges "Select * from [Named Range]"

'single 'quotes' around text values, nothing around numbers -
inside "" for Excel
'WHERE can use any of the following: = < < <= = BETWEEN LIKE
'LIKE wildcard is "%", examples: 'x%' '%x' '%x%'


'Entire Excel column must be uniform datatype (int, date, float, txt,
etc)
'Top row must be labels

Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stCon As String, stSQL As String
Dim i As Long, lnMode As Long

stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & ActiveWorkbook.FullName & ";" _
& "Extended Properties=""Excel 8.0;HDR=YES"";"

stSQL = ActiveSheet.Range("b1")

Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset

cnt.Open stCon
rst.Open stSQL, cnt, adOpenStatic, adLockOptimistic

'A check to see that records actually exist.
If Not rst.EOF Then
With Application
..ScreenUpdating = False
'Collect the present calculation-mode.
lnMode = .Calculation
..Calculation = xlCalculationManual
'Copy the records to the PT Data worksheet.

Workbooks.Add
Range("A1").CopyFromRecordset rst
Range("A1").CurrentRegion.Columns.AutoFit

'Reset the calculation-mode.
..Calculation = lnMode
..ScreenUpdating = True
End With
Else
MsgBox "No records could be found!", vbCritical
End If

'Cleaning up
If CBool(rst.State And adStateOpen) Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) Then cnt.Close
Set cnt = Nothing
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Anyone going from MySql on web server to Excel on desktop?

I found some more on this and posted it to:
http://www.itsdoc.org/tiki/tiki-inde...+VBA+and+MySQL


"Rick" wrote in message
...
Is anyone doing VBA/Excel to MySql stuff? Perhaps with Microsoft
ActiveX DataObjects 2.5 Library (msado15.dll).

Could use some help / simple sample code.

As of about three weeks ago am doing multiple table joins off of
Excel Spreadsheets (all local). VERY COOL! Some simple code below
thanks to (and adapted from) Osgrid.

This is a key part of a larger project. See http://www.ITSDoc.org for
more info.

Rick



sub mySQL1()
'use SQL with Excel tables as input, Excel table as output
'need a ref to Microsoft ActiveX DataObjects 2.5 Library (msado15.dll)
'http://www.ozgrid.com/forum/showthread.php?t=25076

'To attach to tables use any of the following:
' WorkSheet "Select * from [Sheet1$]" (entire used range returned)
' Ranges "Select * from [Sheet1$A1:B10]"
' Named Ranges "Select * from [Named Range]"

'single 'quotes' around text values, nothing around numbers -
inside "" for Excel
'WHERE can use any of the following: = < < <= = BETWEEN LIKE
'LIKE wildcard is "%", examples: 'x%' '%x' '%x%'


'Entire Excel column must be uniform datatype (int, date, float, txt,
etc)
'Top row must be labels

Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stCon As String, stSQL As String
Dim i As Long, lnMode As Long

stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & ActiveWorkbook.FullName & ";" _
& "Extended Properties=""Excel 8.0;HDR=YES"";"

stSQL = ActiveSheet.Range("b1")

Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset

cnt.Open stCon
rst.Open stSQL, cnt, adOpenStatic, adLockOptimistic

'A check to see that records actually exist.
If Not rst.EOF Then
With Application
.ScreenUpdating = False
'Collect the present calculation-mode.
lnMode = .Calculation
.Calculation = xlCalculationManual
'Copy the records to the PT Data worksheet.

Workbooks.Add
Range("A1").CopyFromRecordset rst
Range("A1").CurrentRegion.Columns.AutoFit

'Reset the calculation-mode.
.Calculation = lnMode
.ScreenUpdating = True
End With
Else
MsgBox "No records could be found!", vbCritical
End If

'Cleaning up
If CBool(rst.State And adStateOpen) Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) Then cnt.Close
Set cnt = Nothing
End Sub



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
EXCEL FILES SAVED TO DESKTOP WILL NOT OPEN FROM DESKTOP randy111 Excel Discussion (Misc queries) 3 January 13th 08 10:38 PM
Changing ODBC server (MySQL) Groj Excel Worksheet Functions 0 November 23rd 07 05:09 AM
Excel 2003 Error Cannot Locate the Internet Server or Proxy Server Seabee Excel Discussion (Misc queries) 0 November 20th 05 12:03 AM
MySQL and excel bawar Excel Discussion (Misc queries) 1 January 9th 05 07:57 PM
Import data from mysql on a web server Shaun[_5_] Excel Programming 1 March 7th 04 12:54 AM


All times are GMT +1. The time now is 03:08 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"