I have a form with a subform that displays records, and the user is able to rearrange that subform and save their preferences. This means they can change the width of the columns, the order, hide columns, etc. and save their changes at any time, and those changes are applied when the form next loads. This is done by saving the preferences in a table and then pulling those preferences from the table in the subform's Form_Load event. This all works fine, but I'm trying to add the ability to save frozen columns as well. I'm able to track how many columns are frozen, and I'm also able to restore the order of the columns, so it should be a simple matter to unfreeze all of the columns and then refreeze the first X columns.
I know that I can use 'RunCommand acCmdUnfreezeAllColumns' to unfreeze all of the columns. I also know that I need the focus to be on the form, so I tried to do myForm.setFocus
(where myForm is a reference to the subform) before unfreezing the columns. This gives the error "There is an invalid method in an expression". I thought maybe this was because you can't set focus to a form with enabled controls, so I tried myForm.Controls(0).SetFocus
instead. This doesn't give an error, and it seems to set the focus to the first cell in the subform based on the value of Screen.ActiveControl
(and the fact that the cell has the focus after the form loads). However, I then get the error "The command or action 'UnfreezeAllColumns' isn't available now." on the line RunCommand acCmdUnfreezeAllColumns
. I also thought maybe I was having problems because I was trying to focus in a load event, so I tried calling the repaint method first, but that didn't make any difference. I thought about unfreezing all of the columns in the design view so that I wouldn't need to unfreeze them at runtime, but the user may not have any preferences saved and I want some columns frozen by default.
I'm running out of ideas on this. What exactly needs to happen for the command to unfreeze all columns to work? Or is there an easier way to do this that I'm missing? The solution needs to be versatile enough to work on any subform with any field names. Note that I do have a list of the field names that were present when the user saved their preferences, but I cannot guarantee that they will still all exist when their preferences are restored.