I have a table I want to create in an Access database, that is just a link to another database in ODBC. Currently, this happens via a VB script running inside a module/in Access. I need to replace that with a Powershell script so I can make it work from other areas. I've made the script below:
$DBType = 'ODBC Database'
$DBName = 'ODBC;ServerDSN=MyServerDSN'
$Access = New-Object -ComObject Access.Application
$Connected = $Access.OpenCurrentDataBase("E:\Data\Live\MyAcc.mdb")
$Access.DoCmd.TransferDatabase($AcDataTransferType::acLink, $DBType, $DBName, $AcObjectType::acTable, 'all_per', 'all_per',0,0)
$Disconnected = $Access.CloseCurrentDataBase()
What happens is that this pops up a "Select Data Source" window, and serverDSN is not an option. There is a tab for File Data Source, and a tab for Machine Data Source. In any case, I need the script to not ask for a data source, but use the one specified. Now, I understand it may be asking as the ODBC data source isn't "working" from the script, but I don't know how to fix this. Also, the ODBC connection is a 32-bit DSN...maybe that's the issue, but again, I don't know how to resolve this. The section of the VB code that works for this is:
For Each itm In TableArray
'SendKeys ("{ESC}")
DoCmd.TransferDatabase acLink, "ODBC Database", _"ODBC;DSN=" & strDSN, acTable, itm, itm, No
Next itm
I have been scraping to try and figure out how to get this working in Powershell, but I'm obviously missing something here. Any guidance is appreciated. If there is a better/simpler way, I'm open to suggestions as well.
mpleaf