Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Help with VBA & mySQL Workbench (2 replies)

$
0
0
Hi Guys,

This is my first post on here so please be nice!

Firstly let me say that I am new to using mySQL workbench however I have a good knowledge of VB programming.

I am looking to implement an SQL database that will be accessed using VB code.

I have found a few websites/forums out there with similiar questions however I still find myself stuck in getting started!

Currently I am using the following code to create a connection with my SQL server.. (Found on: http://stackoverflow.com/questions/14575422/open-connection-mysql-vba-excel-2007)

I have Microsoft ActiveX Objects 6.1 Library Reference currently selected in VBA (Excel), however I have tried the code using the 2.8 Objects library to no avail.

--------------------------------------------
Sub test123()

  ' Connection variables
  Dim conn As New ADODB.Connection
  Dim server_name As String
  Dim database_name As String
  Dim user_id As String
  Dim password As String

  ' Table action variables
  Dim i As Long ' counter
  Dim sqlstr As String ' SQL to perform various actions
  Dim table1 As String, table2 As String
  Dim field1 As String, field2 As String
  Dim rs As ADODB.Recordset
  Dim vtype As Variant

  '----------------------------------------------------------------------
  ' Establish connection to the database
  server_name = "127.0.0.1" ' Enter your server name here - if running from a local       computer use 127.0.0.1
  database_name = "smss" ' Enter your database name here
  user_id = "root" ' enter your user ID here
  password = "" ' Enter your password here

  Set conn = New ADODB.Connection
  conn.Open "DRIVER={MySQL ODBC 5.2a Driver}" _
    & ";SERVER=" & server_name _
    & ";DATABASE=" & database_name _
    & ";UID=" & user_id _
    & ";PWD=" & password _

  ' Extract MySQL table data to first worksheet in the workbook
  GoTo skipextract
  Set rs = New ADODB.Recordset
  sqlstr = "SELECT * FROM inbox" ' extracts all data
  rs.Open sqlstr, conn, adOpenStatic
  With Sheet1(1).Cells ' Enter your sheet name and range here
    .ClearContents
    .CopyFromRecordset rs
  End With
  skipextract:

End Sub
'----------------------------------------------

I am using Excel 2013 edition on windows 8, MySQL Workbench v5.2.47



I have created a local server and I am simply wishing to create a connection to this server, retrieve all the values out of one table and paste them onto one excel worksheet.

The Model file name is "Jordan", the Table in this Model is titled "Role"

If you wish for me to provide further details please let me know - this will probably require you explaining how I find/ navigate to them on the mySQL workbench program.


If you could please provide some assistance that would be great. I am a quick learner and once I get over this hurdle I will be on my way to developing some interesting Applications using mySQL databases! :)

Regards
Jordan

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>