MS Access/ VBA : add if condition to vba code -
i have following code :
private sub command66_click() docmd.setwarnings false docmd.deleteobject actable, "table1" docmd.deleteobject actable, "table2" docmd.deleteobject actable, "table3" docmd.setwarnings true end sub
the problem if "table1" not present,i receive vba/debug error. can add condition if script doesn't find "table1" should go further , delete other 2 tables without returning error message?
you mean error trapping? here's example of how can "trap" error - if error occured trying delete table1 ask if want continue:
private sub command66_click() docmd.setwarnings false on error resume next docmd.deleteobject actable, "table1" if err.number > 0 err.clear on error goto 0 if msgbox("there error trying delete table1, want continue?", vbyesno) = vbyes docmd.deleteobject actable, "table2" docmd.deleteobject actable, "table3" end if end if docmd.setwarnings true end sub
Comments
Post a Comment