views:

38

answers:

1

There is an oddity in my VBA module. Sometimes I get a run-time error 2046: The command or action 'RunSQL' isn't available now. When I try it again later, without changing any code, it no longer gives the error, some time later, it does again.

Does anyone know what triggers this run-time error? And how can I avoid it?

I think the problem has something to do with doCmd
The line that shows the error is as follows:

DoCmd.RunSQL "CREATE TABLE " & tableName & " (" & tableDefinition & ")"

There is no table with the same name.

+1  A: 

1st of all creating table in access not with "create table". this is the example to make new table with access vb:

DoCmd.RunSQL ("SELECT '" & Value & "' as [nameOfField] &'"INTO"' & tableName ) 
Yussi Ariefiyono
This seems counter intuitive. How do you specify the datatypes?
neXus
I could see an advantage to this method that allows to fill the table immediately with data, thus specifying the datatype. However, in my case, retrieving all data all at once would require an immense query as the data is scattered across many different tables and many different records within the same table.
neXus