RE: "You must select a company before you can access the table"
The error you are receiving usually suggests that you are attempting to access a table whose data is considered ‘Per-Company’ outside of a company context.
The default value for all tables in the AL syntax is for the data to be ‘Per-Company’ but can be set explicitly with the ‘DataPerCompany’ property.
Code similar to this:
table 50100 MyPerDatabaseTable
{
DataPerCompany = false; // Makes the table per-database
// <Table fields, code, etc.>
}
From your description, I might assume that the problematic code is being executed from within the ‘OnInstallAppPerDatabase’ trigger in your install codeunit. When this trigger is run there is no company context, so any attempt to access a per-company table from there would result in this error.
If you need to perform ‘install’ related tasks for you per-company tables, then they should be done in the ‘OnInstallAppPerCompany’ trigger instead.
See this reading:
https://docs.microsoft.com/en-us/dynamics-nav/developer/devenv-extension-install-code