vba - Loop through Access tables -
I am creating a database in Access that will have multiple tables similar to the same table and all those names will be named sequential Order, such as table_0, table_1 ...
I wanted to know that there is a way to create loops in VBA to make tables first, and to change them, like adding fields easier.
So if I had to create tables, this would be the process, but in VBA
while (i = 0, i <20, i ++) {CREATE TABLE Table_I (field_1in primary key, field 2CRAR (255)); }
In VBA, you can find it through your numbered table names like this Are ...
String down as a dim string I = 0 to 20 strTable = "table_" for a long time & amp; CSTR (i) debug.print statutable next mother but you want to do something other than the table name other than print it. So say that you have already prepared your CREATE TABLE statement, it probably looks like this ... create table table_name (field_1 united primary key, Field 2 text (255)); then you can load that DDL statement in the string variable, then every time your for loop table_name is present value Replace with strTable , and execute that DDL statement. As long as the string is dim, the dim strSql string as the strSql = "create table" ("& amp; vbCrLf & amp;;" field_1 key primary Key, "& vbCrLf & amp; _" field_2 text (255); "I = 0 to 20 strTable =" table_ "& amp; CStr (i) CurrentProject.Connection.Execute Change (strSql, _" table_name " , StrTable) Next I The change () function becomes available with accessibility. If you are using the old access version, you can change your SQL String A different method will be required to handle. If you want to execute a ALTER TABLE statement, you can do this instead. < P> So I think that whatever you want can be done easily with VBA. Although I have uncertainty that you should do so many tables with the same structure generally have a red Error is a design error signal. There is no evidence to draw conclusions That's it's a design error in your case. Otoh, there is no evidence to conclude that not is a design error; -)
Comments
Post a Comment