I have encountered a very usual error that I have tried to resolve for several hours with no luck. The code involved is spread over several procedures, so I don't think it would help to include it here.
As an overview, my code does the following:
Here is the issue: when I run the code a second time I receive a -2147217865 run time error stating that, "Then Microsoft Access database engine could not find the object 'DataQuery1'. Make sure the object exists..."
What is odd is that after I click End in the debug window and then rerun the code then it works fine. So the code works fine every other time I run it!
A couple of other pieces of info:
I have never seen anything like this and it's driving me crazy. I have many other routines in this and other workbooks in which I create named ranges which I then use in select queries and have no issues elsewhere.
I would greatly appreciate any help!!
As an overview, my code does the following:
- Prompts the user to open another workbook.
- Shows a form that prompts the user to select a sheet in the just opened workbook.
- Creates a named range (titled "DataQuery1") on the selected sheet that is then used in the FROM clause in a select query.
- Makes several updates in the current workbook and the just opened workbook.
- Closes the other workbook.
Here is the issue: when I run the code a second time I receive a -2147217865 run time error stating that, "Then Microsoft Access database engine could not find the object 'DataQuery1'. Make sure the object exists..."
What is odd is that after I click End in the debug window and then rerun the code then it works fine. So the code works fine every other time I run it!
A couple of other pieces of info:
- After receiving the error message if I type ?[DataQuery1].Address into the Immediate window it returns the correct range address, so the named range is being created properly.
- If I step through the code and stop it just before the final Exit Sub line then I have no problems when I rerun. This is also very odd.
I have never seen anything like this and it's driving me crazy. I have many other routines in this and other workbooks in which I create named ranges which I then use in select queries and have no issues elsewhere.
I would greatly appreciate any help!!