H
heidii
Hello All:
Below I have pasted the filter code that I have been using on a lot of
my continious forms. It works great, and thank you to who ever
created this code. I found it here on this site.
I would now like to use the same code to filter a subform that is in
datasheet view. My subform is not related to the main form. There is
no records source on the main form. It is just the frame holding my
subform so that I can have combo boxes on the form to use on the
subform. I can not use the combo boxes on the subform as I usually do
as I want this subform to remain in datasheet view so the users can
hide and unhide columns as they wish.
My question is this: How can I use the code I have below to reference
my fields on the subform so they will filter correctly.
I have been trying to implement forms![FRM-RANCH_INFO_SEARCH].[QRY-
RANCH_INFO_RANCH_VIEW1].FORM.[LOT#] but this does not seem to work.
Can anyone help me implement this with the code I have.
Thanks much
Heidi
Private Sub cmdsearch_Click()
Dim blnLOTNUMBER As Boolean
blnLOTNUMBER = IsNull(Me.CBOLOTNUMBER)
Dim blnRANCH As Boolean
blnRANCH = IsNull(Me.CBORANCH)
Dim blnWSDACERTNUMBER As Boolean
blnWSDACERTNUMBER = IsNull(Me.CBOWSDACERTNUMBER)
Dim blnBLOCKTYPE As Boolean
blnBLOCKTYPE = IsNull(Me.cboBLOCKTYPE)
Dim blnSTATUS As Boolean
blnSTATUS = IsNull(Me.cbostatus)
Dim blnCOMMODITY As Boolean
blnCOMMODITY = IsNull(Me.cboCOMMODITY)
Dim blnWSDASITENUMBER As Boolean
blnWSDASITENUMBER = IsNull(Me.CBOWSDASITENUMBER)
Dim blnMASTERVARIETY As Boolean
blnMASTERVARIETY = IsNull(Me.cboMASTERVARIETY)
Dim blnVARIETY As Boolean
blnVARIETY = IsNull(Me.cboVARIETY)
Dim blnYEARPLANTED As Boolean
blnYEARPLANTED = IsNull(Me.cboYEARPLANTED)
Dim blnYEARGRAFTED As Boolean
blnYEARGRAFTED = IsNull(Me.cboYEARGRAFTED)
Dim strLOTNUMBER As String
If blnLOTNUMBER = False Then
strLOTNUMBER = "[LOT#]=" & """" & Me.CBOLOTNUMBER & """"
Else
strLOTNUMBER = ""
End If
Dim strTYPE As String
If blnRANCH = False Then
strRANCH = " [RANCH]=" & """" & Me.CBORANCH & """"
Else
strRANCH = ""
End If
Dim strWSDACERTNUMBER As String
If blnWSDACERTNUMBER = False Then
strWSDACERTNUMBER = " [WSDACERT#]=" & """" & Me.CBOWSDACERTNUMBER &
""""
Else
strWSDACERTNUMBER = ""
End If
Dim strBLOCKTYPE As String
If blnBLOCKTYPE = False Then
strBLOCKTYPE = " [BLOCKTYPE]=" & """" & Me.cboBLOCKTYPE & """"
Else
strBLOCKTYPE = ""
End If
Dim strSTATUS As String
If blnSTATUS = False Then
strSTATUS = " [STATUS]=" & """" & Me.cbostatus & """"
Else
strSTATUS = ""
End If
Dim strCOMMODITY As String
If blnCOMMODITY = False Then
strCOMMODITY = " [COMMODITY]=" & """" & Me.cboCOMMODITY & """"
Else
strCOMMODITY = ""
End If
Dim strWSDASITENUMBER As String
If blnWSDASITENUMBER = False Then
strWSDASITENUMBER = " [WSDA SITE NUMBER]=" & """" &
Me.CBOWSDASITENUMBER & """"
Else
strWSDASITENUMBER = ""
End If
Dim strMASTERVARIETY As String
If blnMASTERVARIETY = False Then
strMASTERVARIETY = " [MASTER VARIETY]=" & """" & Me.cboMASTERVARIETY
& """"
Else
strMASTERVARIETY = ""
End If
Dim strVARIETY As String
If blnVARIETY = False Then
strVARIETY = " [VARIETY]=" & """" & Me.cboVARIETY & """"
Else
strVARIETY = ""
End If
Dim strYEARPLANTED As String
If blnYEARPLANTED = False Then
strYEARPLANTED = " [PLANTED]=" & """" & Me.cboYEARPLANTED & """"
Else
strYEARPLANTED = ""
End If
Dim strYEARGRAFTED As String
If blnYEARGRAFTED = False Then
strYEARGRAFTED = " [GRAFTED]=" & """" & Me.cboYEARGRAFTED & """"
Else
strYEARGRAFTED = ""
End If
Dim strFilter As String
strFilter = ""
If strLOTNUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strLOTNUMBER
Else
strFilter = strFilter
End If
If strRANCH <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strRANCH
Else
strFilter = strFilter
End If
If strWSDACERTNUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strWSDACERTNUMBER
Else
strFilter = strFilter
End If
If strBLOCKTYPE <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strBLOCKTYPE
Else
strFilter = strFilter
End If
If strSTATUS <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strSTATUS
Else
strFilter = strFilter
End If
If strCOMMODITY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strCOMMODITY
Else
strFilter = strFilter
End If
If strWSDASITENUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strWSDASITENUMBER
Else
strFilter = strFilter
End If
If strMASTERVARIETY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strMASTERVARIETY
Else
strFilter = strFilter
End If
If strVARIETY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strVARIETY
Else
strFilter = strFilter
End If
If strYEARPLANTED <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strYEARPLANTED
Else
strFilter = strFilter
End If
If strYEARGRAFTED <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strYEARGRAFTED
Else
strFilter = strFilter
End If
Dim lngLenghOfFilter As Long
lngLenghOfFilter = Len(strFilter)
strFilter = Mid(strFilter, 5, lngLenghOfFilter)
MsgBox strFilter 'you can use it for check
Me.Filter = strFilter
Me.FilterOn = True
End Sub
Below I have pasted the filter code that I have been using on a lot of
my continious forms. It works great, and thank you to who ever
created this code. I found it here on this site.
I would now like to use the same code to filter a subform that is in
datasheet view. My subform is not related to the main form. There is
no records source on the main form. It is just the frame holding my
subform so that I can have combo boxes on the form to use on the
subform. I can not use the combo boxes on the subform as I usually do
as I want this subform to remain in datasheet view so the users can
hide and unhide columns as they wish.
My question is this: How can I use the code I have below to reference
my fields on the subform so they will filter correctly.
I have been trying to implement forms![FRM-RANCH_INFO_SEARCH].[QRY-
RANCH_INFO_RANCH_VIEW1].FORM.[LOT#] but this does not seem to work.
Can anyone help me implement this with the code I have.
Thanks much
Heidi
Private Sub cmdsearch_Click()
Dim blnLOTNUMBER As Boolean
blnLOTNUMBER = IsNull(Me.CBOLOTNUMBER)
Dim blnRANCH As Boolean
blnRANCH = IsNull(Me.CBORANCH)
Dim blnWSDACERTNUMBER As Boolean
blnWSDACERTNUMBER = IsNull(Me.CBOWSDACERTNUMBER)
Dim blnBLOCKTYPE As Boolean
blnBLOCKTYPE = IsNull(Me.cboBLOCKTYPE)
Dim blnSTATUS As Boolean
blnSTATUS = IsNull(Me.cbostatus)
Dim blnCOMMODITY As Boolean
blnCOMMODITY = IsNull(Me.cboCOMMODITY)
Dim blnWSDASITENUMBER As Boolean
blnWSDASITENUMBER = IsNull(Me.CBOWSDASITENUMBER)
Dim blnMASTERVARIETY As Boolean
blnMASTERVARIETY = IsNull(Me.cboMASTERVARIETY)
Dim blnVARIETY As Boolean
blnVARIETY = IsNull(Me.cboVARIETY)
Dim blnYEARPLANTED As Boolean
blnYEARPLANTED = IsNull(Me.cboYEARPLANTED)
Dim blnYEARGRAFTED As Boolean
blnYEARGRAFTED = IsNull(Me.cboYEARGRAFTED)
Dim strLOTNUMBER As String
If blnLOTNUMBER = False Then
strLOTNUMBER = "[LOT#]=" & """" & Me.CBOLOTNUMBER & """"
Else
strLOTNUMBER = ""
End If
Dim strTYPE As String
If blnRANCH = False Then
strRANCH = " [RANCH]=" & """" & Me.CBORANCH & """"
Else
strRANCH = ""
End If
Dim strWSDACERTNUMBER As String
If blnWSDACERTNUMBER = False Then
strWSDACERTNUMBER = " [WSDACERT#]=" & """" & Me.CBOWSDACERTNUMBER &
""""
Else
strWSDACERTNUMBER = ""
End If
Dim strBLOCKTYPE As String
If blnBLOCKTYPE = False Then
strBLOCKTYPE = " [BLOCKTYPE]=" & """" & Me.cboBLOCKTYPE & """"
Else
strBLOCKTYPE = ""
End If
Dim strSTATUS As String
If blnSTATUS = False Then
strSTATUS = " [STATUS]=" & """" & Me.cbostatus & """"
Else
strSTATUS = ""
End If
Dim strCOMMODITY As String
If blnCOMMODITY = False Then
strCOMMODITY = " [COMMODITY]=" & """" & Me.cboCOMMODITY & """"
Else
strCOMMODITY = ""
End If
Dim strWSDASITENUMBER As String
If blnWSDASITENUMBER = False Then
strWSDASITENUMBER = " [WSDA SITE NUMBER]=" & """" &
Me.CBOWSDASITENUMBER & """"
Else
strWSDASITENUMBER = ""
End If
Dim strMASTERVARIETY As String
If blnMASTERVARIETY = False Then
strMASTERVARIETY = " [MASTER VARIETY]=" & """" & Me.cboMASTERVARIETY
& """"
Else
strMASTERVARIETY = ""
End If
Dim strVARIETY As String
If blnVARIETY = False Then
strVARIETY = " [VARIETY]=" & """" & Me.cboVARIETY & """"
Else
strVARIETY = ""
End If
Dim strYEARPLANTED As String
If blnYEARPLANTED = False Then
strYEARPLANTED = " [PLANTED]=" & """" & Me.cboYEARPLANTED & """"
Else
strYEARPLANTED = ""
End If
Dim strYEARGRAFTED As String
If blnYEARGRAFTED = False Then
strYEARGRAFTED = " [GRAFTED]=" & """" & Me.cboYEARGRAFTED & """"
Else
strYEARGRAFTED = ""
End If
Dim strFilter As String
strFilter = ""
If strLOTNUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strLOTNUMBER
Else
strFilter = strFilter
End If
If strRANCH <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strRANCH
Else
strFilter = strFilter
End If
If strWSDACERTNUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strWSDACERTNUMBER
Else
strFilter = strFilter
End If
If strBLOCKTYPE <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strBLOCKTYPE
Else
strFilter = strFilter
End If
If strSTATUS <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strSTATUS
Else
strFilter = strFilter
End If
If strCOMMODITY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strCOMMODITY
Else
strFilter = strFilter
End If
If strWSDASITENUMBER <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strWSDASITENUMBER
Else
strFilter = strFilter
End If
If strMASTERVARIETY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strMASTERVARIETY
Else
strFilter = strFilter
End If
If strVARIETY <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strVARIETY
Else
strFilter = strFilter
End If
If strYEARPLANTED <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strYEARPLANTED
Else
strFilter = strFilter
End If
If strYEARGRAFTED <> "" Then
strFilter = strFilter & Chr(32) & "AND" & Chr(32) & strYEARGRAFTED
Else
strFilter = strFilter
End If
Dim lngLenghOfFilter As Long
lngLenghOfFilter = Len(strFilter)
strFilter = Mid(strFilter, 5, lngLenghOfFilter)
MsgBox strFilter 'you can use it for check
Me.Filter = strFilter
Me.FilterOn = True
End Sub