11/03/2011 01:25 by wawaslope
Start Microsoft Excel 2007 and type "Column1" in "A1", "Column2" in "B1."
Type "A" in "A2", "B" in "A3", "C" in "A4", "D" in "A5."
Type "1" in "B2", "2" in "B3", "3" in "B4", "4" in "B5."
Save your spreadsheet to "C:\" as "book1.xls."
Start Microsoft Office Access 2007 and click "Blank Database," then select "Create." Click "Database Tools" and select "Visual Basic." Click the "Insert" field and select "Module."
Type the following to create the "runSQLExcel" subroutine:
Private Sub runSQLExcel()
Press "Enter."
Type the following to define your variables:
Const adOStatic = 3
Const adLkOpt = 3
Const adCmdString = &H1
Type the following to define and open connections to the Excel spreadsheet:
Set objectConn = CreateObject("ADODB.Connection")
Set objectRst = CreateObject("ADODB.Recordset")
objectConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Book1.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
Type the following to run a SQL statement and open a new Recordset:
objectRst.Open "SELECT * FROM [Sheet1$]", _
objectConn, adOStatic, adLkOpt, adCmdString
Type the following to loop through your Recordset and display results for both of the columns in your spreadsheet:
Do Until objectRst.EOF
MsgBox "Colum1:" & objectRst.Fields.Item("Column1").Value & " " & _
"Colum2:" & objectRst.Fields.Item("Column2").Value
objectRst.MoveNext
Loop
Press "F5" to run your subroutine.
A: Click the Windows "Start" button and select "All Programs." Click "SQL Server," then click "SQL Server Management Studio." The Management St...(more)
A: Click the "Create" tab and select "Query Design." Select the tables you wish to query as displayed in the "Show Table" window, and click "Ad...(more)
A: Start your script with a "DECLARE" block. The "DECLARE" block contains the variables, types and other definitions needed for your script. Ea...(more)
A:Use LIMIT in MySQL Open up MySQL Monitor and log in. Select the database your wish to query by entering the following command: use databas...(more)
A: Open Access, then open the database that you want to query. Click on "Objects" and "Queries." Select "Create Query," then click "SQL Vie...(more)
Added Successfully!
×Voted Successfully!
×You can't vote for yourself
×You can't choose your own answer
×