|
'多条件交叉查询
Private Sub cmderq_Click()
On Error GoTo Err_cmderq_Click
Dim strwhere As String
strwhere = ""
If Not IsNull(Me.Text1) Then
strwhere = strwhere & "([CodeNo] like '" & Me.Text1 & "') AND "
End If
If Not IsNull(Me.Text2) Then
strwhere = strwhere & "([Production] like '" & Me.Text2 & "') AND "
End If
If Not IsNull(Me.Text3) Then
strwhere = strwhere & "([LineName] like '" & Me.Text3 & "') AND "
End If
If Len(strwhere) > 0 Then
strwhere = Left(strwhere, Len(strwhere) - 5)
End If
Me.Production_Sub.Form.Filter = strwhere
Me.Production_Sub.Form.FilterOn = True
Exit_cmderq_Click:
Exit Sub
Err_cmderq_Click:
MsgBox Err.Description
Resume Exit_cmderq_Click
End Sub
'清除条件,回到原始状
Private Sub cmdcls_Click()
On Error GoTo Err_cmdcls_Click
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox
If ctl.Locked = False Then
ctl.Value = Null
Case acComboBox
ctl.Value = Null
Case acCheckBox
ctl.Value = Null
End Select
Next
Me.Production_Sub.Form.Filter = ""
Me.Production_Sub.Form.FilterOn = False
Exit_cmdcls_Click:
Exit Sub
Err_cmdcls_Click:
MsgBox Err.Description
Resume Exit_cmdcls_Click
End Sub
'预览特定的报表
Private Sub cmdrep_Click()
On Error GoTo Err_cmdrep_Click
Dim stDocName, strwhere As String
stDocName = "roduction"
strwhere = Me.Production_Sub.Form.Filter
DoCmd.OpenReport stDocName, acPreview, , strwhere
Exit_cmdrep_Click:
Exit Sub
Err_cmdrep_Click:
MsgBox Err.Description
Resume Exit_cmdrep_Click
End Sub
以上为刘小军做的东东,好像也适合楼主的例子,在下认为以上为一个精典的模板。 |
|