Run-time error only happens sometimes

B

Beginner

Hi!

I am getting a weird run-time error in Access 2007 VBA. I try to open an
ADODB recordset on a query and some times when the code is running it gives
me an error: "Run-time error '-2147217900' Invalid SQL statement; expected
DELETE, INSERT, PROCEDURE, SELECT or UPDATE".

When I debug it, it brings me to this row:
rs2.Open "MyQuery", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

MyQuery exists, because when I press the continue button on my VBA editor,
the code starts to run again without any warnings. At least once the row has
been in the same sub but in a different recordset. Usually after this I get a
second error in another similar situation in another sub, and when I continue
executing the code it continues running normally. The program gives me the
results I want, so it seems that everything goes fine even if I get these
errors. Can the program be corrupted or something, because this happens like
in 10 percent of the times I run it? What should I do?

Thank you for answers!

Beginner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top