以下に示すような 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 データの両方に最大幅を適用するにはどうすればよいですか?