slammedtgs
New member
- Local time
- Yesterday, 18:33
- Joined
- Feb 16, 2013
- Messages
- 4
Hey everyone. I am having trouble with this VBA that I am using to select and append data to an output table. Everything is working fine until the last step. The last step appends all the data to an output table from the initial table. The intermediate steps select the data to output.
This could be done with several sub queries, but I found that to be too slow and cumbersome. The theory in this works great, but I don't know why its not completing.
Any help would be greatly appreciated. :banghead:
"AddExpenseToOutput()" is stopping about halfway through the list of criteria. Initially I thought there might be a null in the list, but it doesn't look like there is after dropping everything into Excel to manipulate.
This code was re-purposed from another project I posted on the forums.
This could be done with several sub queries, but I found that to be too slow and cumbersome. The theory in this works great, but I don't know why its not completing.
Any help would be greatly appreciated. :banghead:
"AddExpenseToOutput()" is stopping about halfway through the list of criteria. Initially I thought there might be a null in the list, but it doesn't look like there is after dropping everything into Excel to manipulate.
Code:
Option Explicit
Dim rstAccount As DAO.Recordset
Dim rstAccounts As DAO.Recordset
Dim CAccounts As String
Dim Item As String
Dim AccountKey As String
Dim Expenses As String
Dim x As Integer
Dim StartTime As String
Dim EndTime As String
' - - - Find Top Accounts in each cost center
Public Function FindTopAccounts()
StartTime = Time()
DoCmd.SetWarnings False
x = 0
CAccounts = ""
DoCmd.OpenQuery "Empty Account List", acViewNormal, acEdit
DoCmd.OpenQuery "Empty Item Summary", acViewNormal, acEdit
DoCmd.OpenQuery "Empty Output", acViewNormal, acEdit
DoCmd.OpenQuery "0 Make Summary Data", acViewNormal, acEdit
DoCmd.OpenQuery "01 - Make_Dept_List", acViewNormal, acEdit
Set rstAccount = CurrentDb.OpenRecordset("Dept_List", dbOpenDynaset) '-- Open Dept_List Table
rstAccount.MoveFirst '-- Select first record
Do 'Run Query for each record in Table
CAccounts = CStr(rstAccount(0))
DoCmd.OpenQuery "02 - Append_top_3_accts", acViewNormal, acEdit
rstAccount.MoveNext
x = x + 1 ' --- Set Counter
Loop While Not rstAccount.EOF '-- Exit Loop when no more records exist
rstAccount.Close '-- Close recordset
Set rstAccount = Nothing
End Function
' - - - Find top Items for each account
Public Function FindTopItems()
DoCmd.SetWarnings False
AccountKey = ""
Set rstAccounts = CurrentDb.OpenRecordset("Account_Key", dbOpenDynaset) '-- Open Dept_List Table
rstAccounts.MoveFirst '-- Select first record
Do 'Run Query for each record in Table
AccountKey = CStr(rstAccounts(0))
DoCmd.OpenQuery "04 - Append_Item_Summary", acViewNormal, acEdit
rstAccounts.MoveNext
x = x + 1 ' --- Set Counter
Loop While Not rstAccounts.EOF '-- Exit Loop when no more records exist
rstAccounts.Close '-- Close recordset
Set rstAccounts = Nothing
End Function
'- - - Append output items to Output Table
Public Function AddExpensesToOutput()
DoCmd.SetWarnings False
Item = ""
Set rstAccounts = CurrentDb.OpenRecordset("Item_Key", dbOpenDynaset) ' -- Open Database Table
rstAccounts.MoveFirst ' -- Select first record to set variable
Do ' -- begin loop
Item = CStr(rstAccounts(0))
DoCmd.OpenQuery "06 - Append Output Table", acViewNormal, acEdit
rstAccounts.MoveNext
x = x + 1 ' --- Set Counter
Loop While Not rstAccounts.EOF ' -- Exit Loop when Item_Key are empty
rstAccounts.Close ' -- Close recordset
Set rstAccounts = Nothing
DoCmd.SetWarnings True
EndTime = Time() ' --- Get Time at end of process
MsgBox ("Started at " & StartTime & vbCr & "Ended at " & EndTime & vbCr & x & " Updates Completed")
End Function
Public Function GetItemKey() As String
GetItemKey = Item ' --- Used in AddExpensesToOutput * Query Criteria Variable
End Function
Public Function GetAccounts() As String
GetAccounts = CAccounts ' --- Used in FindTopAccounts * Query Criteria Variable
End Function
Public Function GetAccountKey() As String
GetAccountKey = AccountKey ' --- Used in FindTopItems * Query Criteria Variable
End Function
This code was re-purposed from another project I posted on the forums.