Results 1 to 12 of 12

Filling data from MySQL db into excel sheet, where ID matches

Threaded View

  1. #1
    Registered User
    Join Date
    02-10-2015
    Location
    Canada eh
    MS-Off Ver
    2010
    Posts
    22

    Post Filling data from MySQL db into excel sheet, where ID matches

    Hey everyone,

    I haven't been able to find any similar examples online to what I'm trying to do.. hoping someone can help out here

    I have a database in MySQL called 'materialsdb' which holds tables for Materials, Manufacturers and Vendors. Materials is the main table of use, linked with foreign keys to Manuf_ID and Vendor_ID.

    EERD.jpg

    I also have an excel workbook for Bill of Materials (BOM). The BOM has columns for part_ID, name, manufacturer, vendor, cost, etc.
    part_ID (actually called CW_ID) and name are the only columns which are populated, the rest are left blank to be filled in from the database.
    The main goal is to be able to check off items in the BOM that will be used for a project, and then click a Macro button, which will populate the empty fields with data from the database tables.
    If item is not checked off, it's columns will not be populated, and possibly filtered so it no longer shows up.

    So far, I have been able to create a button which can import any one of the database tables into specified location in the BOM. However, it just imports the entire table in one location.
    Because both the BOM and the materials table in the db have a column for part_ID, I'm hoping to have it where it will see a match for part_ID and fill in the columns like Manufacturer from the manufacturers table, vendor from vendor table, price from materials table, etc.

    BOM.jpg

    Because the manufacturer and vendor tables are linked to the material tables, I'm not sure if you can use views or joins or something like that, but any help would be appreciated.

    This is what I have so far for the button click:

    Private Sub CommandButton21_Click()
    
    ' Create a recordset object.
    Dim rsMaterialsdb As ADODB.Recordset
    Set rsMaterialsdb = New ADODB.Recordset
    
    'connect to your mysql server
    ADOExcelSQLServer
    
    With rsMaterialsdb
        ' Assign the Connection object.
        .ActiveConnection = cn
        ' Extract the required records.
        .Open "SELECT * FROM Manufacturers"
        ' Copy the records into cell O6 on Sheet1.
        Sheet1.Range("O6").CopyFromRecordset rsMaterialsdb
        
        ' Tidy up
        .Close
    End With
    
    cn.Close    'close connect to db
                    
    End Sub
    Last edited by khelza; 02-12-2015 at 03:59 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. using excel to upload data to MySQL
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-15-2015, 03:48 AM
  2. please let me know can i Update only selected columns
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-01-2014, 02:27 AM
  3. How can i import data from excel csv into mysql
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2014, 05:53 AM
  4. How to save an Excel sheet with commas to MySQL Database
    By cinci-hal in forum Excel General
    Replies: 0
    Last Post: 11-07-2012, 03:29 PM
  5. Getting filtered MySQL Data in Excel
    By drkilljoy in forum Excel General
    Replies: 0
    Last Post: 05-31-2011, 07:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1