B
Bob Ewers
Below is some code for a SQL query that feeds a list box for the output. The listbox no long suffices as the destination for the query result. I think a form is the best option because I'd like to use the PivotTable functionality at some point. I tried and failed to get a generic form to open in datasheet view and display the query result (see REM'd lines). Can someone help me do this.
Private Sub Command99_Click()
'This procedure sets the listbox size and runs the query to fill it.
Dim stpartone As String
Dim stparttwo As String
Dim stpartthree As String
Dim stpartfour As String
Dim stcon1 As String
Dim stcon2 As String
Dim stcon3 As String
Dim stcon4 As String
Dim stcon5 As String
Dim SQLstmt As String
stpartone = rpmattribselect
stparttwo = tradeattribselect
stpartthree = aliasattribselect
stpartfour = aliasgroupselect
stcon1 = pmcondition
stcon2 = lscondition
stcon3 = mktcapcondition
stcon4 = sircondition
stcon5 = induscondition
If Me![ChPM] = True And Me![ChLS] = True And Me![ChMKTCAP] = True And Me![Chindus] = True & _
And Me![ChSir] = True Then
SQLstmt = "SELECT " & stpartthree & _
" [SELECT " & stpartone & _
" WHERE rpm_date >= " & _
Format(startdate, "\#mm/dd/yyyy\#") & _
"AND rpm_date <=" & Format(EndDate, "\#mm/dd/yyyy\#") & _
" UNION SELECT " & stparttwo & _
" WHERE trade_date >=" & Format(startdate, "\#mm/dd/yyyy\#") & _
" AND trade_date <=" & Format(EndDate, "\#mm/dd/yyyy\#") & _
"]. AS [%$##@_Alias]" & _
" WHERE" & stcon1 & " AND " & stcon2 & " AND " & stcon3 & " AND " & stcon4 & " AND " & stcon5 & _
" GROUP BY" & stpartfour
Me![Output].ColumnCount = 6
Me![Output].RowSource = SQLstmt
Me![Output].Requery
'Forms![Outputform].RecordSource = SQLstmt
'Forms![Outputform].Open
Private Sub Command99_Click()
'This procedure sets the listbox size and runs the query to fill it.
Dim stpartone As String
Dim stparttwo As String
Dim stpartthree As String
Dim stpartfour As String
Dim stcon1 As String
Dim stcon2 As String
Dim stcon3 As String
Dim stcon4 As String
Dim stcon5 As String
Dim SQLstmt As String
stpartone = rpmattribselect
stparttwo = tradeattribselect
stpartthree = aliasattribselect
stpartfour = aliasgroupselect
stcon1 = pmcondition
stcon2 = lscondition
stcon3 = mktcapcondition
stcon4 = sircondition
stcon5 = induscondition
If Me![ChPM] = True And Me![ChLS] = True And Me![ChMKTCAP] = True And Me![Chindus] = True & _
And Me![ChSir] = True Then
SQLstmt = "SELECT " & stpartthree & _
" [SELECT " & stpartone & _
" WHERE rpm_date >= " & _
Format(startdate, "\#mm/dd/yyyy\#") & _
"AND rpm_date <=" & Format(EndDate, "\#mm/dd/yyyy\#") & _
" UNION SELECT " & stparttwo & _
" WHERE trade_date >=" & Format(startdate, "\#mm/dd/yyyy\#") & _
" AND trade_date <=" & Format(EndDate, "\#mm/dd/yyyy\#") & _
"]. AS [%$##@_Alias]" & _
" WHERE" & stcon1 & " AND " & stcon2 & " AND " & stcon3 & " AND " & stcon4 & " AND " & stcon5 & _
" GROUP BY" & stpartfour
Me![Output].ColumnCount = 6
Me![Output].RowSource = SQLstmt
Me![Output].Requery
'Forms![Outputform].RecordSource = SQLstmt
'Forms![Outputform].Open