gsilouisvilleic
asked on
Access VBA If Statements
I have a database where information is stored in a table. There is a column names "Errors". If there is at least one value in one of the error fields I want to run a macro, otherwise, if the Errors column is null, I want it to run another macro. I've got the following VBA but it's not functioning correctly because I can't figure out how to add in if there is at least one record, run the macro, if there are no records run the other. Any help would be greatly appreciated.
Private Sub C_Save_Tote_Audit_Info_Cli ck()
If DCount(1, "T_Preview Tote Audit", "IsNull([Errors])") Then
DoCmd.RunMacro "M_Append Tote Information to Master and Reset Good Records"
Else:
DoCmd.RunMacro "M_Append Tote Information to Master and Reset"
End If
End Sub
Thanks,
Cassie
Private Sub C_Save_Tote_Audit_Info_Cli
If DCount(1, "T_Preview Tote Audit", "IsNull([Errors])") Then
DoCmd.RunMacro "M_Append Tote Information to Master and Reset Good Records"
Else:
DoCmd.RunMacro "M_Append Tote Information to Master and Reset"
End If
End Sub
Thanks,
Cassie
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The two answers you selected produce different results. Some people like to award participation points. This is not a practice of which I approve but the choice is yours. In all fairness though, when you choose conflicting answers it would be better for you to at least specify which one actually worked.
Ryan's suggestion produces True when every row in the recordset contains a non-null value.
My suggestion produces True when at least one row in the recordset contains a non-null value
Dale's suggestion gives results similar to mine but only if Errors is numeric. If Errors is text then you can't sum a text field.
Based on your statement -
Ryan's suggestion produces True when every row in the recordset contains a non-null value.
My suggestion produces True when at least one row in the recordset contains a non-null value
Dale's suggestion gives results similar to mine but only if Errors is numeric. If Errors is text then you can't sum a text field.
Based on your statement -
If there is at least one value in one of the error fieldswhich solution is correct?
ASKER
Pat - Your solution was the one that I selected, I did award points for assistance, but I understand where you are coming from. Thanks for your help.
Thanks,
Cassie
Thanks,
Cassie
Open in new window