mardi 1 décembre 2015

Checkboxes for taking input for a sql query in VBA (userform-excel)

I am trying to create a userform - which will have checkboxes for different years and command buttons for different queries. So if for example a user choses three checkboxes -1990,1993, 1995 and then the user clicks on a particular query. Then that query must be executed with that year in going into the "where part of that query" This is my code :-

*

Private Sub CommandButton1_Click()
Dim connection As New ADODB.connection
Dim rst As New Recordset
Dim strConnectionStr As String
Dim Qry As String
strConnectionStr = "Provider=SQLOLEDB;" & "DATA SOURCE=" & _
                  "INITIAL CATALOG=;" & _
                  "UID=; PWD="
Qry = "  SELECT d.Year,d.[University name],d.[School name], COUNT(distinct d.Title) 'Number of paper published'from [dbo].[Ashish$] d where [Business/Non-business]='1'group by d.Year,d.[University name],d.[School name]  order by d.[Year], [Number of paper published] desc;"

ActiveSheet.Cells.ClearContents
connection.Open strConnectionStr
rst.Open Qry, connection
For iCols = 0 To rst.Fields.Count - 1
    Sheets("Query1").Cells(1, iCols + 1).Value = rst.Fields(iCols).Name
Next
Sheets("Query1").Range("A2").CopyFromRecordset rst*`


rst.Close
connection.Close

End Sub

Basically I am unable to take values from checkboxes and use them to inside query statement for the purpose.

I need help . Can anyone guide me on this?




Aucun commentaire:

Enregistrer un commentaire