Eamonn,
Never mind about my question in my previous post.
I would recommend having the code in the click event of a button, rather
than the after update event of each combo box.
But, its your project so I'll do it your way
First off, it was hard for me to keep the combo boxes straight, so I renamed
them. See the code.
Next, you have waaaay to much code. Instead of having identical code in each
of 14 combo boxes, put the code in a sub and call it in the after update
event.
I tested the sql string but I couldn't test that it reutrned the results you
want - but it should be close.
I named the sub that has the "CreateRS" (create record set).
Watch for line wrap. (remember - this is mostly untested!!)
'****** beg code **************
Option Compare Database
Option Explicit
'Layer of funding - Combo28
Private Sub cboFundingLayer_AfterUpdate()
CreateRS
End Sub
' Investor - Combo33
Private Sub cboInvestor_AfterUpdate()
CreateRS
End Sub
'-----------------------
'The rest of the combo boxes (8) Afterupdate event code goes here
'------------------
'Deal DATE Range - Combo75
Private Sub cboDealDateStart_AfterUpdate()
'set the end date to today
Me.cboDealDateEnd = Date
CreateRS
End Sub
'Deal DATE Range - Combo77
Private Sub cboDealDateEnd_AfterUpdate()
CreateRS
End Sub
' Maturity Range - Combo102
Private Sub cboMaturityRangeStart_AfterUpdate()
'set the end date to today
Me.cboMaturityRangeEnd = Date
CreateRS
End Sub
' Maturity Range - Combo104
Private Sub cboMaturityRangeEnd_AfterUpdate()
CreateRS
End Sub
'------------------- MAIN CODE-------------------
Private Sub CreateRS()
Dim QuerySTR As String
Dim GridQry As String
Dim db As Database
Set db = CurrentDb
GridQry = ""
'this is the default
QuerySTR = "Select * From [sheet1] Where ([sheet1].[deal type] <> '' or
[sheet1].[deal type] Is Not Null"
'------These are text------
If Not (Me.cboFundingLayer = "_ALL") And Not Nz(Me.cboFundingLayer, "")
= "" Then 'Layer of funding - Combo28
QuerySTR = QuerySTR & " and [sheet1].[Layer of funding] = '" &
Trim(Me.cboFundingLayer) & "'"
End If
If Not (Me.cboInvestor = "_ALL") And Not Nz(Me.cboInvestor, "") = ""
Then ' Investor - Combo33
QuerySTR = QuerySTR & " and [sheet1].[investor] = '" &
Trim(Me.cboInvestor) & "'"
End If
If Not (Me.cboInvestorType = "_ALL") And Not Nz(Me.cboInvestorType, "")
= "" Then ' Type of Investor - Combo38
QuerySTR = QuerySTR & " and [sheet1].[type of investor] = '" &
Trim(Me.cboInvestorType) & "'"
End If
If Not (Me.cboCountry = "_ALL") And Not Nz(Me.cboCountry, "") = "" Then
'Country - Combo39
QuerySTR = QuerySTR & " and [sheet1].[country] = '" &
Trim(Me.cboCountry) & "'"
End If
If Not (Me.cboDealType = "_ALL") And Not Nz(Me.cboDealType, "") = ""
Then ' Deal type - combo40
QuerySTR = " and [sheet1].[deal type] = '" & Trim(Me.cboDealType) &
"'"
End If
If Not (Me.cboCounterParty = "_ALL") And Not Nz(Me.cboCounterParty, "")
= "" Then 'counterparty - Combo50
QuerySTR = QuerySTR & " and [sheet1].[Counterparty] = '" &
Trim(Me.cboCounterParty) & "'"
End If
If Not (Me.cboDealCCY = "_ALL") And Not Nz(Me.cboDealCCY, "") = "" Then
'Deal CCY - Combo54
QuerySTR = QuerySTR & " and [sheet1].[Deal CCY] = '" &
Trim(Me.cboDealCCY) & "'"
End If
'------These are numbers------
If Not (Nz(Me.cboAmtCCY, 0) = 0) Then 'AMT CCY - Combo56
QuerySTR = QuerySTR & " and [sheet1].[LCL CCY ORDERED] = " &
Val(Trim(Me.cboAmtCCY))
End If
If Not ((Nz(Me.cboLCL_CCY_Start, 0) = 0) And (Nz(Me.cboLCL_CCY_End, 0) =
0)) Then 'LCL CCY Range - Combo72 & Combo74
'original line - using >= and <=
'QuerySTR = QuerySTR & " and [sheet1].[LCL CCY ALLOCATED] >= " &
Val(Trim(Me.cboLCL_CCY_Start)) & " AND [sheet1].[LCL CCY ALLOCATED] <= " &
Val(Trim(Me.cboLCL_CCY_End))
'same line but using BETWEEN
QuerySTR = QuerySTR & " and [sheet1].[LCL CCY ALLOCATED] between " &
Val(Trim(Me.cboLCL_CCY_Start)) & " AND " & Val(Trim(Me.cboLCL_CCY_End))
End If
' here is where you could check that end date is greater than start
date. If not switch the dates before proceding
'------These are dates------
If Not ((Me.cboDealDateStart = #1/1/1900#) And (Me.cboDealDateEnd =
#1/1/1900#)) Then 'Deal DATE Range - Combo75 & Combo77
'QuerySTR = QuerySTR & " and [sheet1].[Deal Date] >= #" &
Trim(Me.cboDealDateStart) & "# AND [sheet1].[Deal Date] <= #" &
Trim(Me.cboDealDateEnd) & "#"
QuerySTR = QuerySTR & " and [sheet1].[Deal Date] between #" &
Trim(Me.cboDealDateStart) & "# AND #" & Trim(Me.cboDealDateEnd) & "#"
End If
'and here also
If Not ((Me.cboMaturityRangeStart = #1/1/1900#) And
(Me.cboMaturityRangeEnd = #1/1/1900#)) Then 'Maturity Range - Combo102
& Combo104
'QuerySTR = QuerySTR & " and [sheet1].[Maturity Date] >= #" &
Trim(Me.cboMaturityRangeStart) & "# AND [sheet1].[Maturity Date] <= #" &
Trim(Me.cboMaturityRangeEnd) & "#"
QuerySTR = QuerySTR & " and [sheet1].[Maturity Date] between #" &
Trim(Me.cboMaturityRangeStart) & "# AND #" & Trim(Me.cboMaturityRangeEnd) &
"#"
End If
' ----for debugging
'MsgBox QuerySTR
' ----for debugging
Me.RecordSource = QuerySTR
Me.Refresh
db.Execute ("Delete from Grid_view")
GridQry = "Insert into Grid_view " & QuerySTR
db.Execute (GridQry)
Me.Sheet1_subform3.Requery
End Sub
Private Sub Form_Load()
Dim db As Database
Set db = CurrentDb
Me.RecordSource = "select * from [sheet1] where ([sheet1].[deal type] <>
'' or [sheet1].[deal type] is not null"
Me.Refresh
db.Execute ("Delete from Grid_view")
db.Execute ("Insert into Grid_view select * from [sheet1] where
([sheet1].[deal type] <> '' or [sheet1].[deal type] is not null")
Me.Sheet1_subform3.Requery
Me.cboFundingLayer = "_ALL"
Me.cboInvestor = "_ALL"
Me.cboInvestorType = "_ALL"
Me.cboCountry = "_ALL"
Me.cboDealType = "_ALL"
Me.cboCounterParty = "_ALL"
Me.cboDealCCY = "_All"
Me.cboAmtCCY = 0
Me.cboLCL_CCY_Start = 0
Me.cboLCL_CCY_End = 0
'you could also use:
'Me.cboDealDateStart = Null
'Me.cboDealDateEnd = Null
'Me.cboMaturityRangestart = Null
'Me.cboMaturityRangeEnd = Null
Me.cboDealDateStart = #1/1/1900#
Me.cboDealDateEnd = #1/1/1900#
Me.cboMaturityRangeStart = #1/1/1900#
Me.cboMaturityRangeEnd = #1/1/1900#
End Sub
'****** end code **************
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
SteveS said:
I've been fighting a cold myself....
Setting the format of the combo boxes is some initial data validation. If
you set the format to General Number for the "AMT CCY" combo (combo56), you
won't be able to enter letters/dates. Same with setting the date combos to
Short Date - you can't enter invalid dates.
------
Sorry, one more question. In the Form_Open() code (and the combo40) you have:
Me.RecordSource = "select * from [sheet1] where ([sheet1].[deal type] <> ''
or [sheet1].[deal type] is not null)"
This is checking to see if [sheet1].[deal type] is not equal to the
string
" or [sheet1].[deal type] is not null"
Is this what you want???