I have been trying to convert an old VBScript to PowerShell. I have successfully converted all but one innocent-looking sub. In the sub, I need to access a textbox on an Access form, but for the life of me, I cannot figure out how get to the individual form (let alone a control on the form). This is the VBScript that I am trying to convert:
Sub checkLinkStatus(fileToLink)
Dim oAccess
Dim oLinkForm
Set oAccess = GetObject(fileToLink).application
oAccess.DoCmd.OpenForm "CFG_CFGLink"
set oLinkForm = oAccess.Forms("CFG_CFGLink")
oLinkForm.Controls("MasterLocation").value = "Production"
'These Subs need to be set to PUBLIC before this can be run.
oLinkForm.Form.MasterLocation_AfterUpdate
oLinkForm.Form.CmdLink_Click
oAccess.quit
Set oAccess = Nothing
End sub
My PowerShell script works okay up to :
functionlinkDB($dbToLink) {
$AccessApp=New-Object-ComObjectAccess.Application
$AccessApp.OpenCurrentDatabase($dbToLink,10)
$AccessApp.DoCmd.OpenForm("CcaCFGLink" )
To access the form, I have unsuccessfully tried many different lines including :
$LinkForm=Get-Item$AccessApp.Forms("CcaCFGLink")
$LinkForm=Get-Item$AccessApp.Forms(0)
$LinkForm=Get-Item$AccessApp.Forms.Item("CcaCFGLink")
$LinkForm=Get-Item$AccessApp.Forms.Item(0)
I have also tried looping through the form collection using a foreach, but to no avail. Of course I am trying to ultimately access a control on the form, but I cannot even access the form! How do I access the form and the control on the form. Any advice would be appreciated. I have looked high and low on the Internet without finding any solutions. Thanks.
Darren White