Hi Jim
I'm not good with VB but one way of doing this would be test for the null condition in the first few lines of the mcrDELETELATEST macro and abend the entire process at that point. {unless someone else can help with the VB code}
If you go into the macro design view (mcrDELETELATEST), Click View -> Conditions, the screen should now have a new column on the left hand side of the macro commands.
Insert three new blank lines at the top of the macro.
Can I run the query at the beginning of the sub and if the result is not null, pop up a MsgBox that will indicate the data has already been imported, and then exit the sub?
To do this bit, you can create the query but can't call on it directly from within the macro. You need to create a form that is based on the query and the macro can look at the value on the form. I discussed a similar problem with another person
here - but be aware that this was for a slightly different problem (although the concept still holds true).
After you have created your query and your new form based on that query - the form should only have one item on it and it will either be null or populated depending on the outcome of your query. In the absence of more info you will need to work this bit out yourself.
Back in the macro design,
First Line = OpenForm (your new form, based on the query you want to test), No conditions
Second Line = MsgBox (set the message box up the way you want it informing the user the import will abend), condition = "IsNull([Forms]![Your Form Name]![The Variable Name])" (without the quotes)
OR if you change a null to zero back in the query then the condition should be "[Forms]![Your Form Name]![The Variable Name] = 0" (without the quotes)
Third Line = StopAllMacros (this is the abend), condition = "IsNull([Forms]![Your Form Name]![The Variable Name])" (without the quotes, or the alternative = 0 version)
The 4th line in the macro will be back to your normal line, with no conditions. You might also edit the macro so that the completion of the mcrDELETELATEST starts the next macro mcrIMPORTDATA, using the "RunMacro" command at then end of your first macro and remove this bit of code
DoCmd.RunMacro "mcrIMPORTDATA"
from this bit of code:
Private Sub Command2_Click()
DoCmd.RunMacro "mcrDELETELATEST"
DoCmd.RunMacro "mcrIMPORTDATA"
On Error GoTo Err_Command2_Click
and as I mentioned earlier, VB is not my strength so I'm not sure of the impact of leaving in this piece of code :
stDocName = "aqryAPPENDWEEKLY"
DoCmd.OpenQuery stDocName, acNormal, acEdit
HTH, Andrew.
