
Originally Posted by
ranman256
If you have a continuous form that shows all records,
build the 'where' clause by cycling thru all the controls,then it filters the list.
it executes after a find button CLICK event
if null, ignore.
if not, apply.
Code:
'----------------
sub btnFilter_click()
'----------------
dim sWhere as string
sWhere = "1=1"
if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
If sWhere = "1=1" Then
Me.FilterOn = False
Else
Me.Filter = sWhere
Me.FilterOn = True
End If
end sub
Or, alter an existing query on the fly to open a select query
Code:
'----------------
sub btnOpenQry_click()
'----------------
dim sWhere as string
dim qdf as querydef
sWhere = " where 1=1"
if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
set qdf = currentdb.querydefs("qsMyQry")
qdf.sql = "Select * from table " & swhere
qdf.close
docmd.openquery qdf.name
end sub
Thank you for the help again ranman256.
I have the first part set
Code:
Private Sub OK_BUTTON_Click()
Dim sWhere As String
Dim qdf As QueryDef
sWhere = " where 1=1"
If Not IsNull(PRODCODE) Then sWhere = sWhere & " and [PROD_CD]='" & PRODCODE & "'"
If Not IsNull(CARRIER) Then sWhere = sWhere & " and [SUB_LOC_CD]='" & CARRIER & "'"
If Not IsNull(MKTCODE) Then sWhere = sWhere & " and [MKT_CD]='" & MKTCODE & "'"
and it seems to like it but When I try to use the second half to call the query it does not seem to like it.
The qry to call is qry_USED so I have this entered
Code:
set qdf = currentdb.querydefs("qry_USED")
And the sql to the query is as follows
Code:
"SELECT DISTINCTROW WHISC_AECS_EDB.MAINFR_SER_NO, WHISC_AECS_EDB.PROD_CD, WHISC_AECS_EDB.SUB_LOC_CD, ALL_ACCESSORIES.MKT_CD, WHISC_AECS_EDB.MOD_CD, WHISC_AECS_EDB.REF_NO, WHISC_AECS_EDB.PHYS_BUDG_CTR, WHISC_AECS_EDB.EQUIP_STAT_CD, WHISC_AECS_EDB.PHYS_STAT_CD, WHISC_AECS_EDB.RECVD_DT, ALL_ACCESSORIES.SO_NO _FROM (WHISC_AECS_EDB INNER JOIN WHISC_JIT_CARRIER ON WHISC_AECS_EDB.SUB_LOC_CD = WHISC_JIT_CARRIER.CARRIER) INNER JOIN ALL_ACCESSORIES ON WHISC_AECS_EDB.MAINFR_SER_NO = ALL_ACCESSORIES.MAINFR_SER_NO
GROUP BY WHISC_AECS_EDB.MAINFR_SER_NO, WHISC_AECS_EDB.PROD_CD, WHISC_AECS_EDB.SUB_LOC_CD, ALL_ACCESSORIES.MKT_CD, WHISC_AECS_EDB.MOD_CD, WHISC_AECS_EDB.REF_NO, WHISC_AECS_EDB.PHYS_BUDG_CTR, WHISC_AECS_EDB.EQUIP_STAT_CD, WHISC_AECS_EDB.PHYS_STAT_CD, WHISC_AECS_EDB.RECVD_DT, ALL_ACCESSORIES.SO_NO
HAVING (((WHISC_AECS_EDB.PHYS_BUDG_CTR) <> "1XF0") And ((WHISC_AECS_EDB.PHYS_STAT_CD) = "024"))
ORDER BY WHISC_AECS_EDB.SUB_LOC_CD "
Then the final piece
Code:
& swhere qdf.close docmd.openquery qdf.name
Again I appreciate your help on this.