help re: acCmdFreezeColumns

  • Thread starter Thread starter AndyB
  • Start date Start date
A

AndyB

I have an open table and I want to freeze two columns once it is open. I
have for the time being created a custom toolbar that opens for the user to
do this without looking for the menu item. However I would much rather have
the columns frozen already. I have tried the following code:

DoCmd.OpenTable "28DayPeriod", acNormal, acEdit

me![FirstName].setfocus
DoCmd.RunCommand acCmdFreezeColumn
Me![lastname].setfocus
DoCmd.RunCommand acCmdFreezeColumn

It does not work it can't find the fields Firstname and Lastname.

I have the table open in the datasheet view.

If I get ride of the two setfocus lines then just the first column is
frozen.

Any help

Andy B
 
Andy,
Does the query that is the record source for your form
have the fields FirstName and lastname in it?
Geof Wyght
 
Yes however the query that makes the new table that I have is a "make table"
query and thus the name of the table is different. But yes the field names
are the same.

Andy
 
Since you are using the Me object, I assume that this is
happening in a form. If so, go into the design view of
your form, click on View, Feild List. Do you see FirstName
and LastName in the list?
Geof Wyght
 
Since you are using the Me object, I assume that this is
happening in a form. If so, go into the design view of
your form, click on View, Feild List. Do you see FirstName
and LastName in the list?
Geof Wyght
 
The form I created just is used for buttons that launch different events
ie;., I am using a createTable button with a built in VBA query that makes
a new table. It is in that table that I want to freeze the columns.
During the last few minutes I even tinkered with the idea of creating a
form to go with the table and then attempted to freeze the columns. I get
the error The command action is not available now.


Andy B
 
AndyB said:
I have an open table and I want to freeze two columns once it is
open. I have for the time being created a custom toolbar that opens
for the user to do this without looking for the menu item. However I
would much rather have the columns frozen already. I have tried the
following code:

DoCmd.OpenTable "28DayPeriod", acNormal, acEdit

me![FirstName].setfocus
DoCmd.RunCommand acCmdFreezeColumn
Me![lastname].setfocus
DoCmd.RunCommand acCmdFreezeColumn

It does not work it can't find the fields Firstname and Lastname.

I have the table open in the datasheet view.

If I get ride of the two setfocus lines then just the first column is
frozen.

Any help

Andy B

The columns you want to freeze are not on "Me", they are on the
datasheet you just opened. Try this:

DoCmd.OpenTable "28DayPeriod", acViewNormal

With Screen.ActiveDatasheet
.Controls("FirstName").SetFocus
RunCommand acCmdFreezeColumn
.Controls("LastName").SetFocus
RunCommand acCmdFreezeColumn
End With

There may be a simpler way to do it, but this seems to work.
 
Andy,
I'll try and re-create that. I haven't used that
technique before. Did you see Dirk Goldgar's reply? Did
it help?
Geof Wyght
 
It worked!!!!

Thank you very much. Geof also to you. You had me thinking about
other techniques.


Andy B
 
One more thing however. I don't quite understand the concept because I tried
to add the additional statements
runcommand.accmdsortascending to sort both columns but it did not work. Why
would it not work?


ANdy B
 
AndyB said:
One more thing however. I don't quite understand the concept because
I tried to add the additional statements
runcommand.accmdsortascending to sort both columns but it did not
work. Why would it not work?

What was your code, and in what way did it not work?
 
I have tried many a different combination of

With Screen.ActiveDatasheet
. Controls("Fname").SetFocus
RunCommand acCmdFreezeColumn
RunCommand acCmdSortAscending
. Controls("Lname").SetFocus
RunCommand acCmdFreezeColumn
RunCommand acCmdSortAscending


End With

The different combination consists of moving the CmdSortAscending command. I
have even tried after the WITH statement.

In all the cases the second column LName is sorted but the first column is
not?


Andy B
 
AndyB said:
I have tried many a different combination of

With Screen.ActiveDatasheet
. Controls("Fname").SetFocus
RunCommand acCmdFreezeColumn
RunCommand acCmdSortAscending
. Controls("Lname").SetFocus
RunCommand acCmdFreezeColumn
RunCommand acCmdSortAscending


End With

The different combination consists of moving the CmdSortAscending
command. I have even tried after the WITH statement.

In all the cases the second column LName is sorted but the first
column is not?

That makes perfect sense, because the sort is only being applied to the
single column that has the focus when you execute the RunCommand.
There's probably a way to select both columns before sorting, but
there's an easier way. Try this:

With Screen.ActiveDatasheet
.Controls("Fname").SetFocus
RunCommand acCmdFreezeColumn
.Controls("Lname").SetFocus
RunCommand acCmdFreezeColumn
.OrderBy = "Lname, Fname"
.OrderByOn = True
End With
 
Thank you very much. I have to say you know your stuff. I struggled with
that for quite a while.



Andy B
 
Back
Top