I have a block of code that imports data from an xls file. Opens the recordset and does some field updates and calculations. I think the If statements within my loop are really slowing down the processing.
Pls take a look and advise how I can make this code more efficient. Thanks
Pls take a look and advise how I can make this code more efficient. Thanks
Code:
Sub UpdateImportData()
Dim db As DAO.Database
Set db = CurrentDb
Dim FileType As String
Dim ImpDate As Date
Dim ETAYear As Integer
Dim Datatype As String
Dim NewImport As String
FileType = Forms!FileImport.FileType
ImpDate = Forms!FileImport.[Last File Imported Date]
ETAYear = Forms!FileImport.ETAYear
ETAMonth = Forms!FileImport.ETAMonth
Datatype = "Financials"
NewImport = "SELECT PRMFinancials.[Client Code], PRMFinancials.PCCode, PRMFinancials.Value, PRMFinancials.FileCode, " & _
"PRMFinancials.CientGroup , PRMFinancials.[ETA Month], PRMFinancials.[ETA Year], PRMFinancials.Type, PRMFinancials.ImportDate " & _
"FROM PRMFinancials WHERE (((PRMFinancials.FileCode) Is Null));"
Dim rstPRMFinancials As DAO.Recordset 'acts like a table or query object
Set rstPRMFinancials = db.OpenRecordset(NewImport) 'Opens the table
rstPRMFinancials.MoveFirst
'______________________________________________________________________________
Do Until rstPRMFinancials.EOF
Dim Amt As Double
If FileType = "Reversal Last Month Accruals" Or FileType = "Reverse Download next month" Or FileType = "Actuals" Or FileType = "Reverse Manual Adj" Then
Amt = (rstPRMFinancials![Value] * -1)
Else: Amt = rstPRMFinancials![Value]
End If
rstPRMFinancials.Edit
rstPRMFinancials![FileCode] = FileType
rstPRMFinancials![ImportDate] = ImpDate
rstPRMFinancials![Value] = Amt
rstPRMFinancials![ETA Year] = ETAYear
rstPRMFinancials![ETA Month] = ETAMonth
rstPRMFinancials![Type] = Datatype
rstPRMFinancials.Update
rstPRMFinancials.MoveNext
Loop
rstPRMFinancials.Close
'________________________________________________________________________________
'Update the Client Group field based on the lookup table
Dim clientgroup As String
clientgroup = "UPDATE PRMFinancials INNER JOIN PRMClientList ON PRMFinancials.[Client Code] = " & _
"PRMClientList.[Client Code] SET PRMFinancials.CientGroup = [PRMClientLIst].[client group]" & _
"WHERE (((PRMFinancials.CientGroup) Is Null));"
db.Execute clientgroup
[code]