Passing ComboBox Value to an Underlying Forn (1 Viewer)

JamesJoey

Registered User.
Local time
Today, 10:17
Joined
Dec 6, 2010
Messages
608
I know this should be easy but I haven't done this in a while.
I want to set the Focus to a Field on an underlying form by passing a ComboBox Value on a form called frmDvdFind. It has the ComboBox and a Command Button
The ComboBox's Row Source is a table.
This form is called from the underlying form.
After selecting a row in the combo box I want to be able to press the command button and set the focus to a field on the underlying form but I'm not having any luck,

Code:
Private Sub cmdFind_Click()
   
   Dim vCbo As String

   vCbo = "Me!cboFieldName.Value"
    
    Forms!frmDvd!vCbo.SetFocus
        
End Sub

The error says it can't find the field vCbo.

This must be second nature to most but not to me,
James
 

MarkK

bit cruncher
Local time
Today, 07:17
Joined
Mar 17, 2004
Messages
8,181
What is an "underlying form?" Is that a subform, or just a form that hosts the combo?
After selecting a row in the combo box I want to be able to press the command button and set the focus to a field on the underlying form
Is the SetFocus related to the ComboBox selection, and if so, how?
Code:
Private Sub cmdFind_Click()
   
   Dim vCbo As String             [COLOR="Green"]'this variable is local to this routine[/COLOR]
   vCbo = "Me!cboFieldName.Value" [COLOR="Green"]'and it contains this exact literal string[/COLOR]
   
[COLOR="Green"]   'Forms!frmDvd!vCbo refers to a control on a form, and is not related in 
   'any way to the vCbo variable in this routine
[/COLOR]   Forms!frmDvd!vCbo.SetFocus 
        
End Sub
In short, it's not clear to me what you are trying to do.
 

Ranman256

Well-known member
Local time
Today, 10:17
Joined
Apr 9, 2015
Messages
4,337
You don't need BOTH select a combo and a button.
The combo AFTERUPDATE event can fire the same as a button click,
 

boerbende

Ben
Local time
Today, 16:17
Joined
Feb 10, 2013
Messages
339
What about
Forms!mainformName.ChildFormName.Form.fieldonform.SetFocus
 

JamesJoey

Registered User.
Local time
Today, 10:17
Joined
Dec 6, 2010
Messages
608
I wanted to create a search form for a split form.
Problem is with the split form, one must first set the focus to a field before clicking Find Next button on Find and Replace dialog.
Otherwise it won't find anything.

This was just a though.
I'm also using list boxes as an alternative to the datasheet side of a split form.
Find works fine with the forms with a list box.
 

JamesJoey

Registered User.
Local time
Today, 10:17
Joined
Dec 6, 2010
Messages
608
What is an "underlying form?" Is that a subform, or just a form that hosts the combo?

Is the SetFocus related to the ComboBox selection, and if so, how?
Code:
Private Sub cmdFind_Click()
   
   Dim vCbo As String             [COLOR="Green"]'this variable is local to this routine[/COLOR]
   vCbo = "Me!cboFieldName.Value" [COLOR="Green"]'and it contains this exact literal string[/COLOR]
   
[COLOR="Green"]   'Forms!frmDvd!vCbo refers to a control on a form, and is not related in 
   'any way to the vCbo variable in this routine
[/COLOR]   Forms!frmDvd!vCbo.SetFocus 
        
End Sub
In short, it's not clear to me what you are trying to do.

Yes it is.
The combo box is populated with the field names of the underlying form.
Once a row in the combo box is selected I want a button when clicked sets the focus to the field name selected in the combo box in the underlying form.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:17
Joined
May 7, 2009
Messages
19,242
will this work:
Code:
Private Sub cmdFind_Click()
   
   Dim vCbo As String             'this variable is local to this routine
   vCbo = Me!cboFieldName.Value 'and it contains this exact literal string
   
   'Forms!frmDvd!vCbo refers to a control on a form, and is not related in 
   'any way to the vCbo variable in this routine
   Forms!frmDvd.Controls(vCbo).SetFocus 
        
End Sub
 

JamesJoey

Registered User.
Local time
Today, 10:17
Joined
Dec 6, 2010
Messages
608
That worked fine!

I learn something every day.

Thanks to all for the help,
James
 

Users who are viewing this thread

Top Bottom