[ 本帖最后由 qp370982 于 2008-12-22 19:12 编辑 ]作者: qp370982 时间: 2008-12-22 20:40
那位老师帮帮我,谢谢,感激涕零作者: qp370982 时间: 2008-12-22 23:28
那位老师帮帮我,谢谢,感激涕零作者: Henry D. Sy 时间: 2008-12-23 08:31 http://www.office-cn.net/forum.p ... mp;page=2#pid389904作者: yesterday 时间: 2008-12-23 08:40
我想这样作可能好一些:因为导入方法是对表操作的,所以你首先要把筛选结果临时放在一个表或查询中。假定临时表为temp,在导出按钮中加入sql,delete * from temp
"insert into temp selete * from 表1 where 籍贯= 选项值
然后采用 TransferSpreadsheet方法作者: yesterday 时间: 2008-12-23 08:48
版主 的帖子很厉害,强烈建议参考使用作者: qp370982 时间: 2008-12-23 13:06
求老师帮忙给改改,在下没学过vb,只学过c,这是老板要的,谢谢,作者: qp370982 时间: 2008-12-23 13:43
求老师帮忙给改改,在下没学过vb,只学过c,这是老板要的,谢谢,作者: Henry D. Sy 时间: 2008-12-23 20:29
Private Sub Command13_Click()
Dim Qdf As DAO.QueryDef
Dim rs As New ADODB.Recordset
Dim strSQL As String, strCriteria As String
Dim ctl As Control
If IsNull(Me.Text14) Then
MsgBox "Enter the Path frist"
Me.Text14.SetFocus
Exit Sub
End If
Set Qdf = CurrentDb.QueryDefs("Q")
For Each ctl In Me.Controls
If TypeOf ctl Is OptionButton Then
If ctl Then
strCriteria = strCriteria & "'" & ctl.Name & "',"
End If
End If
Next
If strCriteria = "" Then
strSQL = "select * from 表1 order by 籍贯"
Else
strSQL = "select * from 表1 where 籍贯 in (" & strCriteria & ") order by 籍贯"
End If
Qdf.SQL = strSQL
strSQL = "select distinct 籍贯 from Q"
With rs
.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do While Not .EOF
Set Qdf = CurrentDb.QueryDefs("Out")
strSQL = "select * from 表1 where 籍贯='" & .Fields(0) & "'"
Qdf.SQL = strSQL
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Out", Me.Text14, , .Fields(0)
.MoveNext
Loop
.Close
End With
Set rs = Nothing
Set Qdf = Nothing
End Sub
[ 本帖最后由 Henry D. Sy 于 2008-12-23 20:31 编辑 ]作者: qp370982 时间: 2008-12-23 23:42
保存路径能设置为对话框形式吗,谢谢作者: Henry D. Sy 时间: 2008-12-24 08:10
Dim ctl As Control
Private Sub Command13_Click()
Dim Qdf As DAO.QueryDef
Dim rs As New ADODB.Recordset
Dim strSQL As String, strCriteria As String
Dim strPath As String
Dim diaFs As FileDialog
Set diaFs = Application.FileDialog(msoFileDialogSaveAs)
With diaFs
.Title = "导出为........"
.Show
End With
If diaFs.SelectedItems.Count > 0 Then
strPath = diaFs.SelectedItems(1)
End If
If strPath = "" Then
strPath = CurrentProject.Path & "\out.xls"
ElseIf Right(strPath, 4) <> ".xls" Then
strPath = strPath & ".xls"
End If
Set Qdf = CurrentDb.QueryDefs("Q")
For Each ctl In Me.Controls
If TypeOf ctl Is OptionButton Then
If ctl Then
strCriteria = strCriteria & "'" & ctl.Name & "',"
End If
End If
Next
If strCriteria = "" Then
strSQL = "select * from 表1 order by 籍贯"
Else
strSQL = "select * from 表1 where 籍贯 in (" & strCriteria & ") order by 籍贯"
[ 本帖最后由 Henry D. Sy 于 2008-12-24 08:11 编辑 ]作者: qp370982 时间: 2008-12-24 11:26
Dim diaFs As FileDialog提示用户定义类型未定义作者: Henry D. Sy 时间: 2008-12-24 11:29
需要引用 Microsoft Office 11