Selecting combobox value with code

pozzo

Registered User.
Local time
Today, 00:53
Joined
Jan 23, 2004
Messages
26
I have a form with a combobox and if form "Mala_dir_para_Grupos" is open the code chooses one value under ItemData(1) as the combo default value.

Else, if form "Mail_para_Grupos" is open the code chooses another value under ItemData(0) as the combo default value. See code below:

If fIsLoaded("Mala_dir_para_Grupos") = True Then
Me.ThisForm = Me.ThisForm.ItemData(1)
Else
If fIsLoaded("Mail_para_Grupos") = True Then
Me.ThisForm = Me.ThisForm.ItemData(0)
End If

It works OK but does´nt really select the option, only shows it.

I need an extra manual work to select the default value showed.

I would like the code to do the complete work!

Any help?

Thanks in advance.

Renato
 
Code:
If fIsLoaded("Mala_dir_para_Grupos") = True Then
   Me.MyCombo = Me.MyCombo.ItemData(1)
ElseIf fIsLoaded("Mail_para_Grupos") = True Then
   Me.MyCombo = Me.MyCombo.ItemData(0)
End If
Call MyCombo_Click

.
 
CyberLynx

Thanks for you answer.

Sorry but it didn´t work yet.

The combo choice is OK but I still need to select it manually from the combo.

What code should I put in MyCombo_Click?

Thanks

Renato
 
It works OK but does´nt really select the option, only shows it.

Well....What does it do now when it's selected? What is the underlying code or Macro that is run when the Combo Item is selected?

The way I interpret your initial post (and I an probably wrong with this) is this:

You have a Main Form and in it there is a Combo Box (let's say it's named myCombo). In this very same Form you have a means of some kind to open any one of two Forms (Mala_dir_para_Grupos or Mail_para_Grupos). Depending upon which Form is opened, the myCombo Combo Box within the Main Form is automatically supplied a value contained within that Combo Box.

If this is he case then it is the Two Forms which require code and not the Main Form. For example: Let's say the Main Form is open, by whatever means the Mala_dir_para_Grupos Form is opened. As the Mala_dir_para_Grupos Form opens, code within the OnOpen event of that Form fires and automatically sets the value within the Main Forms' myCombo Combo Box. The code within the OnOpen event for the Mala_dir_para_Grupos Form may look like this:

Code:
Private Sub Form_Open(Cancel As Integer)
   Dim frm As Form
   Set frm = Forms("[COLOR="Red"][I]MainFormName[/I][/COLOR]")

   If IsLoaded(frm.Name) = True Then
      frm.myCombo = frm.myCombo.ItemData([B][COLOR="Blue"]1[/COLOR][/B])
   End If
   Set frm = Nothing
End Sub

On the other hand, if the Mala_para_Grupos Form opens, code within the OnOpen event of that Form fires and automatically sets the Main Forms' myCombo Combo Box with a different desired value. The code within the OnOpen event for the Mala_para_Grupos Form may look like this:
Code:
Private Sub Form_Open(Cancel As Integer)
   Dim frm As Form
   Set frm = Forms("[I][COLOR="Red"]MainFormName[/COLOR][/I]")

   If IsLoaded(frm.Name) = True Then
      frm.myCombo = frm.myCombo.ItemData([B][COLOR="Blue"]0[/COLOR][/B])
   End If
   Set frm = Nothing
End Sub

.
 

Users who are viewing this thread

Back
Top Bottom