|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
帮你简单写了点,基本结构是这样的,具体的自己可以再完善一下- Private Sub CommandButton1_Click()
- Dim Cnn As New ADODB.Connection
- Dim Rs As New ADODB.Recordset
- Dim Sq1 As String
- Cnn.Open "provider=Microsoft.jet.OLEDB.4.0;Jet OLEDB:Database Password=123;data source=" & ThisWorkbook.Path & "\数据源请不要点击和删除该文件夹\进货最原始录入查询.MDB"
- Sq1 = "Select * from 出货 where 1=1 "
- If Me.ComboBox1.Text <> "" Then
- Sq1 = Sq1 + " and 日期>=#" & Me.ComboBox1.Text & "#"
- End If
-
-
- If Me.ComboBox2.Text <> "" Then
- Sq1 = Sq1 + " and 日期<=#" & Me.ComboBox2.Text & "#"
- End If
-
-
- If Me.ComboBox3.Text <> "" Then
- Sq1 = Sq1 + " and 款号='" & Me.ComboBox3.Text & "' "
- End If
-
-
- If Me.ComboBox4.Text <> "" Then
- Sq1 = Sq1 + " and 颜色='" & Me.ComboBox4.Text & "' "
- End If
-
-
- If Me.ComboBox5.Text <> "" Then
- Sq1 = Sq1 + " and 数量=" & Me.ComboBox5.Text & " "
- End If
-
-
- Sq1 = Sq1 + " order by 日期"
-
-
-
-
- Rs.Open Sq1, Cnn, adOpenKeyset, adLockOptimistic
-
- Sheet2.Range("a2").CopyFromRecordset Rs
-
- Rs.Close
- Cnn.Close
- Set Rs = Nothing
- Set Cnn = Nothing
- End Sub
复制代码 |
|