其中方法二可写成如下函数:
Function Fieldname(tbname As String) As String
'参数:tbname为表或查询名称
Dim rs As New ADODB.Recordset
Dim i As Long
rs.Open tbname, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs.Fields.Count
Fieldname = Fieldname & rs.Fields(i).Name & ";"
Next
End Function
可把参数tbname写为一个查询的字符串,如:
"select 字段1,字段2,字段5 from 表名 where 字段5 = ‘中国导弹制造股份公司'"作者: 风啸啸 时间: 2010-2-26 12:42
学习。作者: caibo_T 时间: 2010-2-27 11:12
问题解决了
Function ToWordFields() As String
Dim ctl As Control
Dim strSQL As String
Dim strTemp(100) As String
Dim i As Integer
ToWordFields = ""
'扫描子窗体上所有的控件,如果是文本框或者组合框,就判断是否被用户隐藏了
For Each ctl In Me.自动生成word表格_人员信息_子窗体.Form.Controls
'注意,这个判断还能继续添加,比如复选框也可以
If ctl.ControlType = acTextBox Or _
ctl.ControlType = acComboBox Then
'如果用户隐藏了列,就说明用户不需要打印,在组织SQL语句的时候也不加进去了
If ctl.ColumnHidden = False Then
strTemp(ctl.ColumnOrder - 1) = "[" & ctl.ControlSource & "]"
Else
strTemp(ctl.ColumnOrder - 1) = ""
End If
End If
Next
For i = 0 To 99
If (strTemp(i) <> "") Then
If (ToWordFields = "") Then
ToWordFields = strTemp(i)
Else
ToWordFields = ToWordFields & "," & strTemp(i)
End If
End If
Next i
'Debug.Print ToWordFields
End Function