Code to Test Condition and Save Record to Excel

K

Ken Hudson

I have the following schema:

[ARDC.txt]
Format=FixedLength
ColNameHeader=False

Col1=DocID Text Width 6
Col2=Space2 Text Width 2
Col3=Date Date Width 8
Col4=Space4 Text Width 2
Col5=Type Text Width 20
Col6=Space6 Text Width 1
Col7=Status Text Width 11
Col8=Space8 Text Width 1
Col9=TT Text Width 4
Col10=Space10 Text Width 1
Col11=ClAmt Text Width 11
Col12=BillAmt Text Width 11

I have the following code:

Option Explicit
Sub OpenRSFromText()
Dim oConn As ADODB.Connection
Dim rsInput As ADODB.Recordset
Dim strPath As String

strPath = "F:\DATA\XCELData\MACROS\AR\"
Set oConn = New ADODB.Connection
Set rsInput = New ADODB.Recordset

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPath & ";" & _
"Extended Properties=""text;HDR=NO;FMT=FixedLength"""

rsInput.Open "SELECT * FROM ARDC.txt", _
oConn, adOpenStatic, adLockOptimistic, adCmdText

....need help here...

End Sub

I want to test each record from ARDC.txt. If ClAmt <> BillAMT, I want to
copy that record into my workbook.

1. Can I/should I define the ClAmt and BillAmt fields as numbers? (Double
precision)
If so, How?

2. What code would I use in the macro to test the condition and copy the
records into Excel?

TIA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top