Results 1 to 9 of 9
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Code for 'DonorID' (XP)

    My database includes two primary tables, tblDonors and tblDonations, to hold information about items donated to a charity auction. We publish a program that lists the items and the donors. Some donors do not wish to be identified by name in the program

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Code for 'DonorID' (XP)

    The problem is that the onopen event is too early. The data is not available yet.

    It would be quicker to move the calculation to the underlying query.

    Create a calculated field in the query Display: iif([Friend],"Friend of BRCC.",[DonorID])

    Then add this field to the report.

    If you want to keep doing it in code, you would need to do it once for each record, so the code would need to be in the format event for the detail section of the report.
    Regards
    John



  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Code for 'DonorID' (XP)

    I hadn't thought of putting it in the query! That's the perfect solution. Thanks, John!

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Code for 'DonorID' (XP)

    John: The first problem I ran into was a data type mismatch. The field, DonorID, in tblDonations is a lookup field. It stores a number, but displays the name. I decided to get rid of that problem by replacing the DonorID field with the actual DonorName (text) field from tblDonors. So then I rewrote the code as follows:

    IIf([tbl_Donations].[Friend],"Friend of BRCC.",[DonorName]

    Now I don't get any error messages, but the query still displays the real donor name in records where it's supposed to show the alternate text. One more thing: When I preview the query, I get a parameter prompt: "tblDonations.Friend". What am I overlooking?

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Code for 'DonorID' (XP)

    The query does not recognise [tbl_Donations].[friend] as the Friend field .

    Perhaps you have mis-spelt it somewhere. Is friend in tbl_donations or tbl_donors?

    If you can't see the problem, remove the calculated field, then rebuiild it this way.

    Add the Friend field to the query, and make sure it correctly displays. Then rebuild the calculated field around what is there, perhaps in stages.

    DisplayName: friend

    When that works,

    DisplayName: iif([friend],"Friend of BRCC.",[DonorName])
    Regards
    John



  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Code for 'DonorID' (XP)

    It works now, John, although I finally had to change the Friend field from a Yes/No format to Text. (If the donor is a "friend," the field shows Friend; otherwise, it's null.) I'm not sure I understand why it wouldn't work with the Yes/No field, but it works...and that's what I need.

    Thank you!

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Code for 'DonorID' (XP)

    That's a mystery to me.

    It should work with a yes/no field, but the important thing is that it now works somehow!
    Regards
    John



  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Code for 'DonorID' (XP)

    Maybe you need to change it to:

    DisplayName: iif([friend]=True,"Friend of BRCC.",[DonorName])

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Code for 'DonorID' (XP)

    Bingo! That did it! And it works with the Yes/No field.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •