Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option Group to Return a Text Value in Table 1

Status
Not open for further replies.

PharmaFun

Programmer
Jul 30, 2003
30
CA
Hello,

I'm very very new to Access and not too knowledgeable, so please be patient. I have an option group within a form designating male or female gender that returns a value of 1 and 2 respectively to a table. I'd like it to return "M" or "F" in the table instead. How can I do that?

Thanks,
PharmaFun
 
Hi PharmaFun,

Option groups can only return numeric data, rather than text, which is one of their major drawbacks.

You can use the following code to obtain the value

Select Case Me.optGender
Case 1
txtGeneder = "M"
Case 2
txtGender = "F"
End Select

John
 
Thanks John for the tip...

I used the code, and I get the following error (sorry, I'm very amateurish at this stuff):

Compile error: Method or data member not found

And the part highlighted is ".optGender"

What does that mean? What should I do?

Thanks,
PharmaFun
 
Sorry - well done for spotting the error (totally unintentional, honest). It shoud be the name of the frame enclosing the option buttons. The word "me" refers to the current form.

This will create a variable called txtGender with the value that you want.

John


 
Hi John....thanks again. No worries about the earlier error...it happens to the best of us! So I added this event to my gender options box:

Private Sub Gender_AfterUpdate(Cancel As Integer)
Select Case Me.Gender
Case 1
txtGender = "M"
Case 2
txtGender = "F"
End Select

End Sub

But now when I click on the male or female option, I get:
Procedure Declaration does not match description of event.

I know, I know...I'm a pest...but please help.

Thanks,
Dean
 
Dean,

Remove the (Cancel As Integer) from the top line of the code.

This is because there is no cancel parameter for the afterupdate event. The BeforeUpdate event does have it - and you can use this to stop the event being run by using Cancel = True in the code.

John
 
Did anyone remember to add

dim txtGender

above the select case statement?
 
completly off the theme, but the 'exercise' doesn't really 'add' to the app in any useful manner. Disparaging comments re the usefulness of the control aside, implementing the db to accept the string (single character) vs. the numeric value does little to enhance the app. In the general sense, "Users" should not be looking (directly) at the table and display of the data via forms / reports can either use the same option group (prefereable)as the data-entry prpcess or do the conversion 'on the fly' using the already noted conversion.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top