我有一个 Microsoft Access VBA 文件,如下所示。
Sub ExportTextFileDelimited(FileName As String, _
DataSet As String, _
Delimiter As String, _
TextQualifier As String, _
WithFieldNames As Boolean)
On Error GoTo ExportTextFile_Err
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Directory As String
Dim MyString As String, strSQL As String
Dim strDS As String
Dim I As Integer
Open FileName For Output As #1
Set cnn = CurrentProject.Connection
rst.Open DataSet, cnn, adOpenForwardOnly, adLockReadOnly
If WithFieldNames Then
For I = 0 To rst.Fields.Count - 1
MyString = MyString & TextQualifier & rst(I).Name & TextQualifier & Delimiter
Next I
MyString = Left(MyString, Len(MyString) - 1)
Print #1, MyString
End If
rst.MoveFirst
Do While Not rst.EOF
MyString = ""
For I = 0 To rst.Fields.Count - 1
'check for text datatype (202)
If rst(I).Type = 202 Then
MyString = MyString & TextQualifier & _
rst(I)
Else
MyString = MyString & rst(I)
End If
Next I
MyString = Left(MyString, Len(MyString) - 2)
Print #1, MyString
rst.MoveNext
Loop
ExportTextFile_Exit:
' Close text file.
Close #1
rst.Close
Set cnn = Nothing
Exit Sub
ExportTextFile_Err:
MsgBox Err.Description
Resume ExportTextFile_Exit
End Sub
此代码工作正常,它输出Query.txt
包含以下数据的文件:
请查看并参考此示例图像。
我的问题是,如何为 AMAL 和 SAMANTHA GAMAGE 数据应用最大宽度?