Hi all,
I really have tried to figure this out but can't. I think Google may ban me soon!! (jk)
I am building a budget database and have a expense entry form that I want to populate some text controls with data from a pre-existing query to let the user know how much was spent in the category they chose from a combo box so far in the current month. The data pieces I want from the pre-existing query (which works fine) are: the category budget for the month and how much is remaining (or isn't). The query by itself always pulls up at least 40 records so there are plenty of rows to go through.
I have written the code below but it will not populate the controls I put an incrementing counter "i" in to see how far the do while loop gets. When I get an error the counter is at zero o it's never reaching the incrementing assignment. I know there's a hundred ways to skin a cat (can we say that anymore?) but I only need one. Any suggestions would be appreciated.
Here's the code:
Private Sub cboCategoryName_AfterUpdate()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim errtext As String
Dim i As Integer
On Error GoTo Err_Name
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryCurrentMonthSpend", dbOpenDynaset)
rst.MoveFirst
i = 0
Do While Not rst.EOF
If rst![Category] = Me.cboCategoryName Then
Me.[txtCategory] = rst![Category]
Me.[txtCurrentSpend] = rst![Spent]
Me.[txtCategoryBudget] = rst![Budget Amount]
Me.[txtBudgetRemaining] = rst![Budget Amount] - rst![Spent]
'we got what was needed. Now exit
Exit Do
rst.MoveNext
i = i + 1
End If
Loop
' Cleanup
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub
Err_Name:
MsgBox ("There was an error! " & "i Value = " & i)
End Sub
Any suggestions? Be kind, I'm still a newbie
Thanks!
-tmguru
I really have tried to figure this out but can't. I think Google may ban me soon!! (jk)
I am building a budget database and have a expense entry form that I want to populate some text controls with data from a pre-existing query to let the user know how much was spent in the category they chose from a combo box so far in the current month. The data pieces I want from the pre-existing query (which works fine) are: the category budget for the month and how much is remaining (or isn't). The query by itself always pulls up at least 40 records so there are plenty of rows to go through.
I have written the code below but it will not populate the controls I put an incrementing counter "i" in to see how far the do while loop gets. When I get an error the counter is at zero o it's never reaching the incrementing assignment. I know there's a hundred ways to skin a cat (can we say that anymore?) but I only need one. Any suggestions would be appreciated.
Here's the code:
Private Sub cboCategoryName_AfterUpdate()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim errtext As String
Dim i As Integer
On Error GoTo Err_Name
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryCurrentMonthSpend", dbOpenDynaset)
rst.MoveFirst
i = 0
Do While Not rst.EOF
If rst![Category] = Me.cboCategoryName Then
Me.[txtCategory] = rst![Category]
Me.[txtCurrentSpend] = rst![Spent]
Me.[txtCategoryBudget] = rst![Budget Amount]
Me.[txtBudgetRemaining] = rst![Budget Amount] - rst![Spent]
'we got what was needed. Now exit
Exit Do
rst.MoveNext
i = i + 1
End If
Loop
' Cleanup
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub
Err_Name:
MsgBox ("There was an error! " & "i Value = " & i)
End Sub
Any suggestions? Be kind, I'm still a newbie

Thanks!
-tmguru