Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

freezing column runcommand fails 1

Status
Not open for further replies.

MePenguin

Technical User
Oct 31, 2003
107
0
0
SE
This is probably a syntax problem...

I have a dynamically created form that is used as a subform, I want to freeze a column on the subform when the main form opens. The following code works if used in the subform's OnOpen event:

Code:
    CODE.ColumnHidden = True
    [SpeciesName].ColumnWidth = 3500 
    [SpeciesName].Locked = True
    [SpeciesName].SetFocus
    DoCmd.RunCommand acCmdFreezeColumn

...but I can't have it there since the subform is deleted and recreated when needed (or can I add the code on creation?).

If I put the equivalent into the main form's OnOpen even:

Code:
    [SFBugsCountsheet].Form![CODE].ColumnHidden = True   
    [SFBugsCountsheet].Form![SpeciesName].ColumnWidth = 3500
    [SFBugsCountsheet].Form![SpeciesName].Locked = True    
    [SFBugsCountsheet].Form![SpeciesName].SetFocus
    DoCmd.RunCommand acCmdFreezeColumn 'error here

it tells me that "The command or action 'FreezeColumn' isn't available now" - runtime error 2046 - at the runcommand line.

Everything else works, and if I use the runcommand line in the immediate window it works, so I can only assume that the subform isn't in a state where the command can be used during the OnOpen event of the main form...?

Anybody know what's going on?

Thanks,




Phil

---------------
Pass me the ether.
 
Just a guess, have you tried On Load?
 
In the fine art of answering my own questions (!), a solution:

I moved the freezecolumn command into the onclick event sub of the button that opens the mainform...

Code:
DoCmd.OpenForm "F2000CountsheetEditor"
    Forms![mainform]![subform].Form![SpeciesName].SetFocus
    DoCmd.RunCommand acCmdFreezeColumn

Don't really understand it though, can anyone explain?

Phil

---------------
Pass me the ether.
 
Just got your tip Remou, thanks - I'll try that if my solution springs any consequences.

Phil

---------------
Pass me the ether.
 
It is, as far as I remember, what you said. The controls are not really in a usable state in the On Open event for the form. When you add the stuff to the button, the form is already opened, so you can access the controls. The On Load event occurs after the On Open event, and the controls are usable at that stage.
 
MePenguin said:
[blue]I moved the freezecolumn command into the onclick event sub of the button that opens the mainform . . . Don't really understand it though, can anyone explain?[/blue]
Sure! . . . take a good look at the command . . .
Code:
[blue]DoCmd.RunCommand acCmdFreezeColumn[/blue]
. . .and imagine you have three forms open. How does the method know which form to act on? . . . It will be the form that has the [blue]focus[/blue] or the form where a control has the [blue]focus![/blue]

When you had the code in the OnOpen event you didn't set the [blue]focus[/blue] to the subform. Then when you moved the code to the button, focus was set with a seperate command!

Now . . . since [blue]a form with subform opens from the inner most subform out to the mainform[/blue], your initial setup should work. You just have to set focus first . . .

The are other methods of DoCmd which have the same [blue]focus[/blue] dependency. [purple]You'll know because you can't set the form in any of the arguements . . .[/purple]





Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1, shouldn't
Code:
    [SFBugsCountsheet].Form![SpeciesName].SetFocus
    DoCmd.RunCommand acCmdFreezeColumn 'error here
in the main form's OnOpen sub set the focus to the correct control on the subform? (as in original post)

What I don't understand is why I can lock, hide, and alter width of the column in that sub, but not freeze it...

Phil

---------------
Pass me the ether.
 
MePenguin . . .

Apparently [blue]SpeciesName[/blue] did not receive the focus. I've simulated a subform and in the Open event of the mainform I have:
Code:
[blue]   [subFormName].SetFocus
   [subFormName]!FieldName.SetFocus
   DoCmd.RunCommand acCmdFreezeColumn[/blue]
Had no problems!


Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan1, have a star for persistance!

Phil

Phil

---------------
Pass me the ether.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top