I have a large segment of code, and it all works, except when there is a user error.
There is a text box which a user must put a value in, and then click a button to update a table.
If the user leaves the box blank and clicks the button a msg box pops up asking them to fill in a value, if the box contains a value then a series of commands and SQL is run.
Unfortunately, when the box is left blank, the msg box pops up, but then the commands and SQL run anyway.
I guess I may just be missing something really obvious, but I cant get my head around it. this is the block of code that is causing me problems…
If IsNull(Me.TxtStockValue) Then MsgBox "Please Select An Item To Update Stock And Ensure A Value Has Been Entered" Else:
DoCmd.RunSQL SQLDelete1
DoCmd.SetWarnings False
DoCmd.RunSQL SQLStory
DoCmd.RunSQL SQLDelete2
DoCmd.RunSQL SQLUpdate
DoCmd.SetWarnings True
txtStockValue is the txt box which cannot be empty. The else doesn’t seem to be working the way I want.
Thanks
Sam
Try this – in your version only the first statement (SQLDelete1) is part of the else, the rest is always executed.