twoplustwo
Registered User.
- Local time
- Yesterday, 19:46
- Joined
- Oct 31, 2007
- Messages
- 507
Hi all.
I have had a look around the forums for a similar thread but it didn't quite match my requirements.
I am trying to read in a file for each customer in rsCustomer. Each records in the recordset builds the following file path:
R:\Portfolio\GB Consumption Account\B\Bend\Aggregate.FC2
Where the first letter/customer name changes depending on present customer.
Similar code works in Excel and I think I have refernces turned on but I'm a little short on ideas!
Thanks for any help!
I have had a look around the forums for a similar thread but it didn't quite match my requirements.
I am trying to read in a file for each customer in rsCustomer. Each records in the recordset builds the following file path:
R:\Portfolio\GB Consumption Account\B\Bend\Aggregate.FC2
Where the first letter/customer name changes depending on present customer.
Similar code works in Excel and I think I have refernces turned on but I'm a little short on ideas!
Code:
Public Sub TestImport()
Dim db As Database
Dim dtEndDate As Date
Dim dtStartDate As Date
Dim rsCustomer As DAO.Recordset
Dim strCustomer As String
Dim strCustomerLetter As String
Dim strFilePath As String
Dim strFullFilePath As String
Dim strToOpen As String
Dim strRuid As String
Dim strSql As String
Dim xlApp As Excel.Application
Dim xlBookFile As Excel.Workbook
Dim xlRangeToCopy As Excel.Workbook
Dim wb As Excel.Workbook
Set db = CurrentDb
dtStartDate = CDate(Format(#1/4/2009#, "dd/mm/yyyy"))
dtEndDate = CDate(Format(#1/4/2009#, "dd/mm/yyyy"))
strSql = "SELECT Customer FROM tblCustomerExc GROUP BY Customer"
Set rsCustomer = db.OpenRecordset(strSql)
With rsCustomer
If Not .BOF Then
Do While Not .EOF
strCustomer = !Customer
strCustomerLetter = Left(strCustomer, 1)
strFilePath = "R:\Portfolio\GB Consumption Account\"
strToOpen = "\Aggregate.FC2"
strFullFilePath = strFilePath & strCustomerLetter & "\" & strCustomer & strToOpen
Workbooks.OpenText _
Filename:=strFullFilePath, _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=True, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
Other:=False
Loop
End If
End With
Set rsCustomer = Nothing
End Sub
Thanks for any help!