SetFocus and GoToControl cannot set focus

G

Gary Davidson

Hi all,

This one is drving me mad and searching through the NG it would seem
Im not alone.

I have a form where the user selects a product type from a combo box.
Based on their selection a sub category combo displays all models for
that product. Users can enter a new model if it does not exist.

Problem is I need to set the focus back to the first combo box to read
the contents i.e. server or client and then display the appropriate
form for the user to add a new product.

I am using the NotInList. I have tried several variations as my code
will show but with no joy. I just get the run-time error 2110 cannot
move the focus to the control!!!

Private Sub ComboSubCat_NotInList(NewData As String, Response As
Integer)
'Forms!TechInDB!ComboProductID.SetFocus
DoCmd.GoToControl "ComboProductID"
'Me!ComboProductID.SetFocus
Select Case ComboProductID.Text
Case "Server"
'If ComboProductID.Text = "Server" Then
If MsgBox("Server Product Not In Database, Add?", vbYesNo +
vbQuestion, "Please Respond") = vbYes Then
DoCmd.OpenForm "FrmServer", _
Datamode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
If IsLoaded("FrmServer") Then
Response = acDataErrAdded
DoCmd.Close acForm, "FrmServer"
Else
Response = acDataErrContinue
End If
Else
Response = acDataErrContinue
End If
End Select

End Sub

Please tell me where I am going wrong, im still finding my feet in the
access world!

Thanks

Gary
 
S

Sandra Daigle

Hi Gary,

You don't need to setfocus to the combo to access its value or the values of
the other fields in the selected row. To get the value of the bound column
just refer to the 'Value' property. Since the 'Value' property is the
default property you don't have to explicitly refer to it:

if me.ComboProductID = 14 then

Since the 'Text' property of the combo gives you the displayed value (which
might not be the saved value) you can also use the "Column" property to get
to the values in the other fields of the selected row: For example, if the
product descriptions in your example are in the 2nd column of the combo's
rowsource then you could compare this way (note that column(0) refers to the
first column) :

if me.ComboProductID.column(1) = "Server" then
 
G

Guest

Hi, Gary.

AFAIK, Access won't let you change the focus in a NotInList event, but the
good news is you needn't set the focus there to retrieve the value. Simply
remove your statements, and continue with the Select Case statement.

Hope that helps.
Sprinks
 
A

Andi Mayer

On Tue, 18 Jan 2005 08:53:05 -0500, "Sandra Daigle"

additionaly:

your IsLoaded("FrmServer") will never be true

because you open FrmServer with acDialog, therefore it has to be
closed to continue your code
 
D

Dirk Goldgar

Andi Mayer said:
On Tue, 18 Jan 2005 08:53:05 -0500, "Sandra Daigle"

additionaly:

your IsLoaded("FrmServer") will never be true

because you open FrmServer with acDialog, therefore it has to be
closed to continue your code

Not necessarily, Andi. If the form is made invisible, code execution in
the calling routine resumes. I use this technique quite often to
display custom dialogs. On the dialog form, the Cancel button closes
the form, while the OK button merely hides the form, leaving it up to
the calling code to extract information from the form and then close it.
If the calling code finds that the form is not open, that means the
dialog was cancelled.
 
A

Andi Mayer

Not necessarily, Andi. If the form is made invisible, code execution in
the calling routine resumes. I use this technique quite often to
display custom dialogs. On the dialog form, the Cancel button closes
the form, while the OK button merely hides the form, leaving it up to
the calling code to extract information from the form and then close it.
If the calling code finds that the form is not open, that means the
dialog was cancelled.

you are right, I was a little bit to short and assumed to much.
Mostly I do it the oposite way, I write the values into the calling
form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top