+ Reply to Thread
Results 1 to 2 of 2

creating query of table

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    creating query of table

    I am trying to query a sheet, sample data below. The code appears to work but I don't get an output from either the copyfromrecordset or the loop. I am not sure that the query statement is working either but I cannot figure out either way. I would appreciate any suggestions


    Order Material MRPctrlr Bsc start Basic fin. Material description Target qty
    60314960 1227465 M02 2/27/2012 3/1/2012 ANALYZER,BASIC,AUTOSDI,PIC 3
    60316077 1113664 M02 2/15/2012 2/27/2012 KIT,TEST,SDI 5
    60316179 1227465 M02 3/2/2012 3/7/2012 ANALYZER,BASIC,AUTOSDI,PIC 3
    60316525 1234818 M02 2/17/2012 3/9/2012 RO,E4-6600-DLX,460,6,HR(PA) 1
    60316548 3057250 M02 2/21/2012 2/23/2012 RO,E4-ULTRA,380,50,NAM 1
    60316852 1227385 M02 2/27/2012 2/28/2012 KIT,MEMBRANE/HSG ASSY,AG4040 5
    60316853 1226260 M02 2/29/2012 3/1/2012 RO,E2-0750-DLX,115,6 1
    60316855 1230885 M02 2/28/2012 2/29/2012 KIT,EZ4-6600-ECN,460,6,50-75 1
    60316880 1106359 M02 2/27/2012 2/29/2012 FLT,INLINE,AUTO-SDI,0.25TBXTB 4
    60316921 3057250 M02 2/22/2012 2/24/2012 RO,E4-ULTRA,380,50,NAM 1

    Function mysql()
    On Error Resume Next
    
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adCmdText = &H1
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordset = CreateObject("ADODB.Recordset")
    
    objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Users\414004425\Documents\Forms\Vulcan\Vulcan.xlsm;" & _
            "Extended Properties=""Excel 8.0;HDR=Yes;"";"
    
    objRecordset.Open "Select * FROM [Data$] Where MRPctrlr = M02", _
        objConnection, adOpenStatic, adLockOptimistic, adCmdText
    
    
            ThisWorkbook.Worksheets("Data").Range("L1").CopyFromRecordset
    
    
    
    Do Until objRecordset.EOF
        Wscript.Echo objRecordset.Fields.Item("Material description"), _
            objRecordset.Fields.Item("Target qty")
        Cells(12, 12).Value = objRecordset.Fields.Item("Material description").Value
        objRecordset.MoveNext
    Loop
    
    
    
    
    End Function

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: creating query of table

    Why are you using On Error Resume Next? That's a great way of hiding any problems with the code. Remove that line, fix any run-time errors and post back if you still need help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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