Unanswered: Conditional Macro based on query results
OK, here's my situation. I have a database that generates check request forms. An amount is provided for each account. For some of the accounts, the amount is broken down into multiple checks based on a percentage that is in the database. I want to add some additional controls to the database. I already have a query that sums up the percentages. If anything is outside of a small tolerance level I set around 100%, it shows up on the query. If everything is OK, the query is blank. What I would like to do is set up a macro that runs at several points during the process. If the query described above is blank, it will transparent to the user. If something is in the report, an error message will appear. I've searched the web for conditional macro and vba solutions, but everything I try always gives me an error. If I can just figure out how to return a certain value if the query is blank and another value if it isn't, I can do all the rest.
Thanks for the info.....used it as a guide and tried a couple of different things until I got this, which seems to work very well so far. It automatically runs when the percentage editing form is closed, and also before check requests go out.
Const strQueryName = "qryPercentageCheck"
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset(strQueryName)
If Not rs.EOF Then
MsgBox "One or more Profit Centers with multiple checks do not add up to 100%. Please review and correct data on the following report before proceeding", 0, "Percentage Check Error!!"
DoCmd.OpenReport "rptPercentageCheck", acViewPreview