Function ImportLoanSales()
Dim cn As ADODB.Connection
Dim rsTable As ADODB.Recordset
Dim varAllFiles As Variant
Dim strSQL As String
Dim strFile As String
Dim i As Integer
Set cn = CreateObject("ADODB.Connection")
Set rsTable = CreateObject("ADODB.Recordset")
varAllFiles = OpenFiles()
If blnCancel = True Then Exit Function
For i = 0 To UBound(varAllFiles)
strFile = varAllFiles(i)
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Extended Properties=""Excel 8.0;HDR=Yes;MaxScanRows=0;IMEX=0"";"
strSQL = "SELECT * FROM [Sheet1$]"
rsTable.Open strSQL, cn
Do While Not rsTable.EOF
DoCmd.SetWarnings False
strSQL = "INSERT INTO dbo_CustomDatafields" & _
"(" & _
"[LoanID], [Date Funded], [Amount Funded], [Principle Purchase Amount], [Paid to Date], " & _
"[Next Due Date], [Selling Price], [Investor Price %], [Investor SPRP %], " & _
"[Investor Tax Fee], [Investor Flood Fee], [Investor UW Fee], [Investor Misc Fee], " & _
"[SPM to Collect Pymt], [No Pymts SPM to Collect], [Impounds Expected], " & _
"[Impounds Investor Funded], [Impounds Discrepancies], [Buydown Funds Investor], " & _
"[Interest Investor Funded], [Investor Account #], [Investor Servicer LN], " & _
"[Loan Stage], [Act Buy Price], [Totlnv Fee's]" & _
") " & _
"VALUES ('" & _
rsTable.Fields("Loan_ID") & "', '" & _
rsTable.Fields("DateFunded") & "', '" & _
rsTable.Fields("AmountFunded") & "', '" & _
rsTable.Fields("PrinciplePurchaseAmt") & "', '" & _
rsTable.Fields("PaidToDate") & "', '" & _
rsTable.Fields("NextDueDate") & "', '" & _
rsTable.Fields("SellingPrice") & "', '" & _
rsTable.Fields("InvestorPricePerc") & "', '" & _
rsTable.Fields("InvestorSRPPerc") & "', '" & _
rsTable.Fields("InvestorTaxFee") & "', '" & _
rsTable.Fields("InvestorFloodFee") & "', '" & _
rsTable.Fields("InvestorUWFee") & "', '"
strSQL = strSQL & _
rsTable.Fields("InvestorMiscFee") & "', '" & _
rsTable.Fields("FLStoCollectPymt") & "', '" & _
rsTable.Fields("NoPymtsFLStoCollect") & "', '" & _
rsTable.Fields("ImpoundExpected") & "', '" & _
rsTable.Fields("ImpoundsInvestorFunded") & "', '" & _
rsTable.Fields("ImpoundsDiscrepancies") & "', '" & _
rsTable.Fields("BuydownFundsInvestor") & "', '" & _
rsTable.Fields("InterestInvestorFunded") & "', '" & _
rsTable.Fields("InvestorLoanNumber") & "', '" & _
rsTable.Fields("InvestorServicerLnNo") & "', '" & _
rsTable.Fields("LoanStage") & "', '" & _
rsTable.Fields("ActBuyPrice") & "', '" & _
rsTable.Fields("TotInvFees") & _
"')"
' Debug.Print strSQL
DoCmd.RunSQL strSQL
rsTable.MoveNext
Loop
rsTable.Close
cn.Close
Next
DoCmd.SetWarnings True
MsgBox "Done."
End Function
Public Function OpenFiles() As Variant
Dim varFile As Variant
Dim strAllFiles As String
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Title = "Please select one or more Excel files"
.Filters.Clear
.Filters.Add "Excel Worksheets", "*.xls"
If .Show = True Then
For Each varFile In .SelectedItems
strAllFiles = strAllFiles & varFile & "|"
Next
blnCancel = False
Else
MsgBox "You clicked Cancel in the file dialog box."
blnCancel = True
Exit Function
End If
End With
strAllFiles = Left(strAllFiles, Len(strAllFiles) - 1)
OpenFiles = Split(strAllFiles, "|")
End Function