Use Paramater Input with an Table Import MACRO?

  • Thread starter Thread starter kev100 via AccessMonster.com
  • Start date Start date
K

kev100 via AccessMonster.com

I've set up a Macro to Import a non-Access table into an Access table.

In the TransferDatabase macro...there is a field for the source table name.
I currently have the exact name of the source table..and it works fine.

However, I'm needing to prompt the User for the name of the Source table that
is being imported.

There are several tables....any one of which the user may need to import
depending on the task at hand...and the SUFFIX of the tables' names change
often.

Table_101
Table_423
Table_Fri
Table_Tue
Table_57A
Table_NY
....etc

The SECOND part of the table name changes...the "Table_" prefix is the Same
on A ll tables...only the suffix (anything after the _ ) sets it apart.

Is it possible to use some sort of paramater input variable in the source
table field?

Something like Source: Table_[Enter Table Name Suffix:] (?)

I have tried the above syntax....but it does not work...I only used it to try
to illustrate what is needed.

Thanks very much.
 
if you use the

DoCmd.TransferDatabase

action in VBA, you can assign the table name to a string variable, and use
the variable in the action argument for the source table, as

Dim strTableName As String

strTableName = "Table_" & InputBox("Enter the table suffix.")

DoCmd.TransferDatabase acImport, "database type here", _
acTable, strTableName

read up on the TransferDatabase Action in VBA Help to make sure you
understand how to use the arguments. you should probably also include some
code to exit the procedure if the user closes the input box without entering
a suffix, as well as error handling in case an invalid suffix produces an
error on the TransferDatabase action.

hth
 
I'm not much of a VBA programmer....

Do I attaching this code to a button, etc on a form?


Thanks
 
Back
Top