Solved Independant text box value based on a combo value, with enumeration

Etxezarreta

Member
Local time
Today, 21:10
Joined
Apr 13, 2020
Messages
175
Hello everyone,
In a tabular form, a combobox contains 3 rows, and I want to copy the value of the third one in a text box right next to the combo:
to do so, I use an enumeration list:

Code:
Option Compare Database
Option Explicit

Public Enum eListeChoixTypeSf
    Id_semi_fini
    Semi_fini
    Type_semi_fini
End Enum

then on the load event :
Code:
Private Sub Form_Open(Cancel As Integer)
Me.txt_Type_SF.Value = Me.combo_Fk_SemiFini.Column(eListeChoixTypeSf.Type_semi_fini)
End Sub

But nothin appears in my textbox: see below (the etxtboxes are in the second column)
1602754464863.png

It is obvious that I don't use something the right way, but no way to find out.
Thanks in advane for your help.
Etxe
 
I think Enums start at 1 and you column count starts at 0 ?

What happens if you use column 2 hard coded?
 
The use of an Enumeration does not make any sense in this context. You use enumeration if the argument of the called property or method is of an enumeration type. The column property index is of type Integer not of type eListeChoixTypeSf
These values should be Constants and not an enumeration.
IMO the attempted use of an enumeration here makes your code less understandable not more understandable which is the purpose of an enumeration.
Code:
Option Compare Database
Option Explicit

Const Id_semi_fini = 0
Const Semi_fini_Description = 1
Const Type_Semi_fini = 2
 
Last edited:
I think Enums start at 1 and you column count starts at 0 ?

What happens if you use column 2 hard coded?
Code:
Me.txt_Type_SF = Me.combo_Fk_SemiFini.Column(2)

It doesn't work eather
 
Hi. Can you show us the Row Source of your Combobox? Is it a Value List with just those three (3) items in it?
 
Hi. Can you show us the Row Source of your Combobox? Is it a Value List with just those three (3) items in it?
Hi DBguy, the row source is this code:
Code:
SELECT t_ListeSemiFinis.Id_SemiFini, t_ListeSemiFinis.Semi_fini, t_ListeTypesSemiFinis.Type_semi_fini
FROM t_ListeTypesSemiFinis INNER JOIN t_ListeSemiFinis ON t_ListeTypesSemiFinis.Id_type_semi_fini = t_ListeSemiFinis.FK_TypeSemiFini;
 
Hi DBguy, the row source is this code:
Code:
SELECT t_ListeSemiFinis.Id_SemiFini, t_ListeSemiFinis.Semi_fini, t_ListeTypesSemiFinis.Type_semi_fini
FROM t_ListeTypesSemiFinis INNER JOIN t_ListeSemiFinis ON t_ListeTypesSemiFinis.Id_type_semi_fini = t_ListeSemiFinis.FK_TypeSemiFini;
Okay, one more question, what is in the Column Count property? Is it 1?
 
Rereading your post and thinking about it that won't work on a continuous form anyway, and not in the on open event of a form.

Simply use either a join in your underlying query to display the value or copy the combobox and control source, and simply display column 3, make the control locked to avoid someone trying to edit it.
 
The use of an Enumeration does not make any sense in this context. You use enumeration if the argument of the called property or method is of an enumeration type. The column property index is of type Integer not of type eListeChoixTypeSf
These values should be Constants and not an enumeration.
IMO the attempted use of an enumeration here makes your code less understandable not more understandable which is the purpose of an enumeration.
Code:
Option Compare Database
Option Explicit

Const Id_semi_fini = 0
Const Semi_fini_Description = 1
Const Type_Semi_fini = 2
I have been trying for the first time the enum, and I need to use it to fully understand how it works.
Thanks for your explanation.
Etxe
 
Rereading your post and thinking about it that won't work on a continuous form anyway, and not in the on open event of a form.

Simply use either a join in your underlying query to display the value or copy the combobox and control source, and simply display column 3, make the control locked to avoid someone trying to edit it.
Spot on: great solution, so simple and quick, many thanks.
Etxe
 
I have been trying for the first time the enum, and I need to use it to fully understand how it works.

You want to use an enumeration if the procedure receiving the value wants to limit and clarify the choices. You want to use a constant if the thing you are passing needs to be made clear but.
Enum.png

Notice the procedure SetFollowUpDate accepts arguments of type Followup. When I call this procedure it limits my choices to only the acceptable values and better yet gives me intellisese. It also makes the code easier to understand. How you were using it did not make sense because you did not have a procedure anywhere that accepted an argument of eListChoiceTypeSf. A constant would make sense.
 
One more thing with Enums that . You can use built in Access and VBA enums for your own procedures. Even if it is used in a different way. Assume I want the choices for Anywhere, Entire, or Start to represent from where I want to search a string. I can use a preexisting Enum without creating my own if it matches the choices I want.
AccessEnum.png
 

Users who are viewing this thread

Back
Top Bottom