NauticalGent
Ignore List Poster Boy
- Local time
- Yesterday, 23:16
- Joined
- Apr 27, 2015
- Messages
- 6,596
While trying to find a way to change the properties of my db (specifically the ShowDocumentTabs property) with PowerShell, I asked ChatGPT and here was the first response:
That did not work and generated RT error '3061' - too few parameters. I relied this to CPT, here was the response:
This time the error was "Table MSysNavPaneGroupCategories not found. CPT suggested this:
So, I repeat the question: "What System or Hidden table(s) (if any) holds the properties for the current db, and can they be set with a query?"
If you want to modify Access database properties without opening the Access application, you can consider using the Access Database Engine's ACE OLEDB provider to interact with the database. This provider allows you to execute SQL commands against the database without opening Access itself.
Here's an example PowerShell script that uses the ACE OLEDB provider to set the `ShowDocumentTabs` property to `False`:
Code:```powershell # Set the path to the Access database $databasePath = "C:\Path\To\Your\Database.accdb" # Create a connection to the Access database using ADO.NET with ACE OLEDB provider $connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$databasePath;" $connection = New-Object System.Data.OleDb.OleDbConnection($connectionString) try { # Open the database connection $connection.Open() # Set the ShowDocumentTabs property to False $command = $connection.CreateCommand() $command.CommandText = "UPDATE MSysAccessStorage SET ShowDocumentTabs = False" $command.ExecuteNonQuery() Write-Output "ShowDocumentTabs property set to False successfully." } catch { Write-Output "Error occurred: $_" } finally { # Close the connection and release resources in the finally block if ($connection.State -eq 'Open') { $connection.Close() } $connection.Dispose() } ```
In this script, I've used the `MSysAccessStorage` table to represent a system table that may contain the `ShowDocumentTabs` property. However, the actual system table and field names might differ based on the Access version and configuration.
As always, please make sure to have a backup of your database before making changes, and test any script on a copy of your database to ensure it behaves as expected.
That did not work and generated RT error '3061' - too few parameters. I relied this to CPT, here was the response:
I apologize for the confusion. The error may be occurring because the specified table or field name (`MSysAccessStorage`, in this case) might not exist in your database, or the structure might be different.
If you are using Access 2013 or later, you can use the `MSysNavPaneGroupCategories` table to store the Navigation Pane settings. Please note that manipulating system tables directly can be risky, and it's essential to have a backup of your database before making changes.
Here's an updated script that attempts to set the `ShowDocumentTabs` property to `False` using the `MSysNavPaneGroupCategories` table:
Code:```powershell # Set the path to the Access database $databasePath = "C:\Path\To\Your\Database.accdb" # Create a connection to the Access database using ADO.NET with ACE OLEDB provider $connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$databasePath;" $connection = New-Object System.Data.OleDb.OleDbConnection($connectionString) try { # Open the database connection $connection.Open() # Set the ShowDocumentTabs property to False $command = $connection.CreateCommand() $command.CommandText = "UPDATE MSysNavPaneGroupCategories SET ShowDocumentTabs = False" $command.ExecuteNonQuery() Write-Output "ShowDocumentTabs property set to False successfully." } catch { Write-Output "Error occurred: $_" } finally { # Close the connection and release resources in the finally block if ($connection.State -eq 'Open') { $connection.Close() } $connection.Dispose() } ```
Please replace `MSysNavPaneGroupCategories` with the appropriate system table name based on your Access version. If this still doesn't work, you might need to explore alternative methods or consider using VBA within Access to modify these settings programmatically.
This time the error was "Table MSysNavPaneGroupCategories not found. CPT suggested this:
This of course worked - not as written; Access would not quit - so CPT and I played 20 questions getting something that DID work and I'll share that code if anyone wants it. Although it does work and only takes a second, if there is a way to do it with a query, I would like to know. If anything just to gain the knowledge.I appreciate your patience. Access system tables can be version-specific, and their structures may change. If you're unable to find the correct table for your version, and since modifying system tables directly is not recommended, I'll provide an alternative solution using VBA within Access to toggle the `ShowDocumentTabs` property.
Firstly, create a new module in your Access database and add the following VBA code:
Code:```vba Function SetShowDocumentTabs() ' Set the ShowDocumentTabs property to False CurrentDb.Properties("ShowDocumentTabs") = False End Function ```
After saving the module, you can run this function from PowerShell using the `Access.Application` COM object without opening the Access application window. Here's the PowerShell script:
Code:```powershell # Set the path to the Access database $databasePath = "C:\Path\To\Your\Database.accdb" # Create an instance of Access.Application $accessApp = New-Object -ComObject Access.Application try { # Open the Access database in invisible mode $accessApp.OpenCurrentDatabase($databasePath, $false) # Run the VBA function to set the ShowDocumentTabs property to False $accessApp.Run("SetShowDocumentTabs") Write-Output "ShowDocumentTabs property set to False successfully." } catch { Write-Output "Error occurred: $_" } finally { # Quit the Access application $accessApp.Quit() } ```
This script opens the Access database using the `Access.Application` COM object in invisible mode, runs the VBA function to set the `ShowDocumentTabs` property, and then quits the Access application.
Please adjust the `$databasePath` variable with the actual path to your Access database. Test this script on a copy of your database to ensure it behaves as expected.
So, I repeat the question: "What System or Hidden table(s) (if any) holds the properties for the current db, and can they be set with a query?"
Last edited: