【发布时间】:2014-05-07 20:55:53
【问题描述】:
我有一个连续表单,其中表单标题包含过滤选项,详细信息部分包含数据。
我希望能够将其导出到 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
【问题讨论】:
-
为什么不将过滤器放在查询上并导出查询结果?这听起来是一种更简单的方法。
-
根据我的阅读,您不能排除导出的标题行 - 仅在导入时。一种选择是进行导出,然后运行 VBA 代码打开 Excel 文件并删除第 1 行。
-
这不是我要排除的标题行。在我的访问表单的标题中,我创建了未绑定的文本框来搜索所有记录。例如人们可以在文章描述中搜索关键字。当他们找到他们需要的东西(可能是多条记录)时,他们需要能够将这些结果导出到 Excel。但是当我对 docmd.output 执行此操作时,未绑定的文本框每个也成为我的 excel 文件中的一列。
-
您可以将未绑定的文本框放在表单页脚而不是页眉中吗?
-
这是我刚刚发现并测试过的好东西...access-programmers.co.uk/forums/showthread.php?t=149974
标签: ms-access ms-access-2007 vba export-to-excel