我有一个连续的表单,表单标题包含过滤器选项,详细信息部分包含数据。
我希望能够将其导出为excel。基本的VBA代码工作
DoCmd.OutputTo
但是当我导出到Excel时,它还包括每行的表单标题控件。
有没有办法设置一个属性来排除表单标题包含在导出中?基本上,只导出表单详细信息部分?
我不想使用查询
标题中有6个未绑定的txt框: - artnr - Artnr供应商 - 描述 - 文章状态 - 供应商名称 - 供应商编号 我有一个搜索按钮,保存这段代码:
Private Sub cmdSearch_Click()
Dim strWhere As String
Dim lngLen As Long
'artikel zoeken
If Not IsNull(Me.txtSearchArtnr) Then
strWhere = strWhere & "([Material] Like ""*" & Me.txtSearchArtnr & "*"") AND "
End If
'artnr leverancier zoeken
If Not IsNull(Me.txtSearchSupplArt) Then
strWhere = strWhere & "([LiefMat] Like ""*" & Me.txtSearchSupplArt & "*"") AND "
End If
'trefwoord zoeken
If Not IsNull(Me.txtSearchKeyword) Then
strWhere = strWhere & "([Materialkurztext] Like ""*" & Me.txtSearchKeyword & "*"") AND "
End If
'artikelstatus zoeken
If Not IsNull(Me.txtSearchStatus) Then
strWhere = strWhere & "([Status] Like ""*" & Me.txtSearchStatus & "*"") AND "
End If
'leverancier naam zoeken
If Not IsNull(Me.txtSearchSupplName) Then
strWhere = strWhere & "([Name 1] Like ""*" & Me.txtSearchSupplName & "*"") AND "
End If
'leverancier nummer zoeken
If Not IsNull(Me.txtSearchSupplNumber) Then
strWhere = strWhere & "([Lieferant] Like ""*" & Me.txtSearchSupplNumber & "*"") AND "
End If
'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "Geen criteria gevonden", vbInformation, "Geen resultaten."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'Apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
答案 0 :(得分:0)
你写的,用户可以设置过滤器,所以你必须编写像
Me.RecordSource =&#34; SELECT ... FROM table WHERE - 标准 - &#34;
Me.Requery
所以你可以使用SQL语句并将其用于导出,首先必须创建一个查询
Dim sSQL As String
Dim qd As QueryDef
Set qd = CurrentDb.CreateQueryDef("tmp_Query")
qd.SQL = "Select * from T_Personal"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "tmp_Query", "yourfile", True
CurrentDb.QueryDefs.Delete qd.Name
将它包装到一个函数中,这样你就可以在任何地方触发它并传递sql和filename ...
HTH
答案 1 :(得分:0)
我在这里找到了溶剂:
Exporting selected records to excel - hiding certain columns
DoCmd.Echo False
Me.Field1.Visible = False
Me.Field2.Visible = False
Me.Field3.Visible = False
DoCmd.RunCommand acCmdOutputToExcel
Me.Field1.Visible = True
Me.Field2.Visible = True
Me.Field3.Visible = True
DoCmd.Echo True
End Sub
这很简单,对我有用