Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

SetFocus Error

  Asked By: Lisa    Date: Feb 24    Category: MS Office    Views: 1247
  

I'm receiving an error message when I try to use the SetFocus method
to set focus on a combo box in an excel worksheet. The message
is "Object doesn't support this property or method (Error 438)."
The code line is;

cboSheathPumpVol.SetFocus

There are several other controls on the worksheet. This code works
in Visual Basic 6 and I'm experimenting with the VBA in excel.
Any help you can give is appreciated!

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Amir Shaikh     Answered On: Feb 24

I'm afraid that you've answered your own
question here ... Excel doesn't seem to
support the SetFocus method.

I too use SetFocus in VB6, but never
have tried it in Excel. However, I just
did a Help search in both:

-- in VB6, I found an entry for SetFocus
-- in Excel, NOTHING was found.

Read it and weep :(

I use SetFocus such that an anticipated
keyboard entry will be directed to the
correct control.

What is it that you are trying to achieve?
Maybe a workaround can be devised.

 
Answer #2    Answered By: Abriana Rossi     Answered On: Feb 24

The Help files in the VB Script editor on XL 2002 have an entry for
set focus: (copy / paste below).

SetFocus Method
See Also Applies To Example Specifics
Moves the keyboard focus  to the specified command bar control. If the
control is disabled or isn't visible, this method  will fail.

Remarks
The focus on the control is subtle. After you use this method, you
will notice a three dimensional highlight on the control. Pressing the
arrow keys will navigate in the toolbars, as if you had arrived at the
control by pressing only keyboard controls.

expression.SetFocus

expression Required. An expression that returns a CommandBarControl,
CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Example
This example creates a command bar named "Custom" and adds a ComboBox
control and a Button control to it. The example then uses the SetFocus
method to set  the focus to the ComboBox control.

Set focusBar = CommandBars.Add(Name:="Custom")
With CommandBars("Custom")
.Visible = True
.Position = msoBarTop
End With

Set testComboBox = CommandBars("Custom").Controls _
.Add(Type:=msoControlComboBox, ID:=1)
With testComboBox
.AddItem "First Item", 1
.AddItem "Second Item", 2
End With
Set testButton = CommandBars("Custom").Controls _
.Add(Type:=msoControlButton)
testButton.FaceId = 17
' Set the focus to the combo  box.
testComboBox.SetFocus

 
Answer #3    Answered By: Mario Ryan     Answered On: Feb 24

I also looked in the help files and found the entry below for Excel 2002. However, the SetFocus method  does not appear in the pop-up list box  that VBA provides to complete a code line.

I actually stepped through each method in the list box and, although I missed it the first time through, the Activate method seems to do what I need, “setting focus” on the control I want.

 
Answer #4    Answered By: Garry Sanchez     Answered On: Feb 24

I've found a few examples of similar things in Access VBA (esp
related to DAO), where the examples etc in the help files are either
a complete Myth and tell the user completely the wrong keywords /
properties / syntax or else are totally non-existent and just return
a "keyword not found" message.

It can make for a really frustrating learning experience - I should
really start making a list as I go along.

 
Answer #5    Answered By: Chung Tran     Answered On: Feb 24

ok, not sure if it's going to help with help files which are plain
misleading / incorrect, but just to let you know that you can all
sleep soundly now, as I've found my missing ADO / DAO help files.

support.microsoft.com/default.aspx?scid=kb;en-
us;249065&Product=acc2000

 
Didn't find what you were looking for? Find more on SetFocus Error Or get search suggestion and latest updates.




Tagged: