Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
'Darron
'If you would like to try an ADO procedure copy and paste 'the following to the code sheet of "sheet1" 'place a cmd button on Sheet1 'Remember: 'To use ADO objects in an application add a reference 'to the ADO component. From the VBA window select 'Tools/References< check the box ' "Microsoft ActiveX Data Objects 2.x Library" 'This procedeure calls a parameterized query from Access Private Sub CommandButton1_Click() Dim CMD As New ADODB.Command Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset db_Name = ("C:\Program Files\Microsoft Visual Studio\VB98\NWind.mdb") cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & db_Name & ";" & ", , , adConnectAsync;" cnn.Open CMD.ActiveConnection = cnn CMD.CommandText = "[Sales By Year]" CMD.CommandType = adCmdUnknown Dim Param As ADODB.Parameter Set Param = New ADODB.Parameter Param.Name = "Date1" Param.Type = adDate Param.Value = InputBox("Starting", App_Name, Date) ' Param.Value = Worksheets("Sheet1").Range("J18").Value ' InputBox("Beginning Date", App_Name, #1/1/1995#) Param.Direction = adParamInput CMD.Parameters.Append Param Set Param = New ADODB.Parameter Param.Name = "Date2" Param.Type = adDate Param.Value = InputBox("Ending", App_Name, Date) Param.Direction = adParamInput CMD.Parameters.Append Param rs.CursorLocation = adUseClient Set rs = CMD.Execute rs.MoveFirst Dim rg As Range Set rg = ThisWorkbook.Worksheets(1).Range("a1") Worksheets("Sheet1").Range("a1").CopyFromRecordset rs rg.CurrentRegion.Columns.AutoFit 'Close the connection cnn.Close Set cnn = Nothing 'Destroy the Recordset Set rs = Nothing Exit Sub End Sub 'Good Luck 'TK |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert hard coded query criteria to Parameter Query | Excel Discussion (Misc queries) | |||
Excel 2007 / MS Query - editing existing query to another sheet | Excel Discussion (Misc queries) | |||
Edit Query from Excel will not open query in MSQuery | Excel Programming | |||
How to use a Access Query that as a parameter into Excel database query | Excel Discussion (Misc queries) | |||
Stop to modify the SQL query manually entered into query ! | Excel Programming |