none
Option Group for gender RRS feed

  • Question

  • Hi
    .
    I wanna use option group in a form for choosing gender(male,female)
    but option group returns number instead of the words "male" or "female"

    how can I have these words in gender column when I press male or female button ?

    ------------------------------
    P.S:
    I read somewhere that the solution is to add a text box and then invisible it and bound it to the gender column
    and . unbound the option group and in property sheet after update . write a code for changing numbers 1 and 2 with words male and female

    please help what code i should write ?
    Sunday, August 23, 2015 2:58 PM

Answers

  • The reason things are this way is because it satisfies the majority of cases where the database wants to work with numbers, and the human with text.

    Since you seem to be struggling with code, I would recommend a zero-code solution:
    Change the field in the table to Number.
    Add a new table with GenderID autonumber PK, and GenderName text6, required
    Enter the two records for male and female.
    Use the Relationships window to draw the relation between the two tables and enforce it.

    That's it. Your app still works, saving numbers to the main table.
    If you ever want to display what that number means, use a query to join with tblGenders.

    This is a VERY common technique and you will see MANY more uses for it. For example a Status field may be saving StatusID, and looking up the available statuses in its own table. The combobox to select Status from has 2 columns: a hidden ID column to satisfy the database, and a visible StatusName column to satisfy the humans.


    -Tom. Microsoft Access MVP

    Sunday, August 23, 2015 3:41 PM
  • Hi. I agree with Tom's solution. But if you feel that an additional table with only two records would use too much resources, you can use a little expression in your forms or queries to accommodate the humans.

    So, still store the 1 or 2 in the table but in your query, use a calculated column like:

    txtGender: IIf([Gender]=1,"Male","Female")

    Usually, you would use a combobox for something like this in a form with the following settings:

    Row Source: 1;"Male";2;"Female"
    Row Source Type: Value List
    Bound Column: 1
    Column Count: 2
    Column Widths: 0

    Hope that helps...

    Sunday, August 23, 2015 4:40 PM

All replies

  • The reason things are this way is because it satisfies the majority of cases where the database wants to work with numbers, and the human with text.

    Since you seem to be struggling with code, I would recommend a zero-code solution:
    Change the field in the table to Number.
    Add a new table with GenderID autonumber PK, and GenderName text6, required
    Enter the two records for male and female.
    Use the Relationships window to draw the relation between the two tables and enforce it.

    That's it. Your app still works, saving numbers to the main table.
    If you ever want to display what that number means, use a query to join with tblGenders.

    This is a VERY common technique and you will see MANY more uses for it. For example a Status field may be saving StatusID, and looking up the available statuses in its own table. The combobox to select Status from has 2 columns: a hidden ID column to satisfy the database, and a visible StatusName column to satisfy the humans.


    -Tom. Microsoft Access MVP

    Sunday, August 23, 2015 3:41 PM
  • Hi. I agree with Tom's solution. But if you feel that an additional table with only two records would use too much resources, you can use a little expression in your forms or queries to accommodate the humans.

    So, still store the 1 or 2 in the table but in your query, use a calculated column like:

    txtGender: IIf([Gender]=1,"Male","Female")

    Usually, you would use a combobox for something like this in a form with the following settings:

    Row Source: 1;"Male";2;"Female"
    Row Source Type: Value List
    Bound Column: 1
    Column Count: 2
    Column Widths: 0

    Hope that helps...

    Sunday, August 23, 2015 4:40 PM
  • thakns a lot
    Sunday, August 23, 2015 7:29 PM
  • thanks a lot
    Sunday, August 23, 2015 7:29 PM
  • I like both solutions in general.

    @ the DB guy

    How would you compensate that calculated field if more options were available? ie. prefer not to disclose

    Also, it looks like female is default, so if someone forgets to choose then they are defaulted as a Female?

    Can it be setup like

    1. Default = No Choice Made
    2. Male
    3. Female
    4. Prefer not to answer
    5. Other

    Just curious about it,

    Thank you!!!


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Sunday, August 23, 2015 8:02 PM
  • @KCDW. My rule of thumb is for one or two options (sometimes maybe three), I will probably not use a table. If you need more records than that, then I would recommend using a table as Tom suggested above. So, for example, if the options are Yes or No, or Male or Female, or In or Out, then I won't use a table. But if the options are like Yes/No/Maybe, or Low/Medium/High, or Start/Middle/End, or 1st Qtr/2nd Qtr/3rd Qtr/4th Qtr, then I will most likely use a table. Hope that makes sense...
    Sunday, August 23, 2015 8:10 PM
  • But what about for fun?

    Would it be something like..

    txtGender: IIf([Gender]=1,"Male","([Gender]=2,"Female","([Gender]=3,"Prefer Not to Disclose","Not Selected")")")


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Sunday, August 23, 2015 10:00 PM
  • But what about for fun?

    Would it be something like..

    txtGender: IIf([Gender]=1,"Male","([Gender]=2,"Female","([Gender]=3,"Prefer Not to Disclose","Not Selected")")")



    Oh, for fun? I would use something like this:

    txtGender: Choose([Gender],"Male","Female","Prefer Not to Disclose","Not Selected")

    Cheers!

    Sunday, August 23, 2015 10:42 PM