#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    23
    Rep Power
    0

    need to convert the value of a field in an access db to another value


    I have a field in my db called "Gender" it can have values "Male" or "Female". I will be printing this information onto a pre-printed form which has cross-boxes/check-boxes for male and female. I have created fields in a query called "MaleX" and "FemaleX". These fields contain the same value as gender. I need two functions. In the "MaleX" field it will convert the value in the Field to an "X", if the value is "Male" else it will convert it to a null. In the "FemaleX" field it will convert the value in the Field to an "X", if the value is "Female" else it will convert it to a null.

    I know this sounds easy but when I can get the value into the field.

    In the query, I have the fields as
    "FemaleX: convertFemale([Gender])"

    and

    "MaleX: convertMale([Gender])"

    The code I tried doesn't work but probably explains the problem better than I have

    "
    Public Function convertFemale(strInput As String)

    If (strInput = "Female") Then

    strInput = "X"

    Else

    strInput = null

    End If

    End Function
    "

    Hope someone can help I really don't know very much about vb
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    23
    Rep Power
    0
    Rather than using an additional VB function, I used the IIf statement, which evaluates a condition and returns a value depending on whether the condition is true or false.

    I changed the calculated fields in your query to:
    FemaleX: IIf([Gender]="Female","X","")
    MaleX: IIf([Gender]="Male","X","")

    That did it

IMN logo majestic logo threadwatch logo seochat tools logo