Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Assign a value to an Object (2000)

    I have a form with a calculated field which I then want to pass to an ordinary text field to store the value in the table. There is nothing unusual about the text field - it's just a number (single) and I can manually enter into it. However, when I try to pass a value to the text box I get the message 'You can't assign a value to this field'
    The form just comes from the table - not even a query. If you open the FrmOrganSupport on the attched file you will see what I mean. What am I doing wring?
    Thanks
    Allison

  2. #2
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Cincinnati, Ohio, USA
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign a value to an Object (2000)

    The code is balking on this:

    <pre>TxtOrganCount = TxtOrgansSupported
    </pre>


    TxtOrgansSupported is linked to the field [OrgansSupported]
    TxtOrganCount has athe following formula:

    <pre>=IIf([ChkAdvResp]=True,1,0)+IIf([ChkBasicResp]=True,1,0)+
    IIf([ChkAdvCardio]=True,1,0)+IIf([ChkBasicCardio]=True,1,0)+
    IIf([chkrenal]=True,1,0)+IIf([chkneuro]=True,1,0)+IIf([chkderm]=True,1,0)
    +IIf([chkliver]=True,1,0)+IIf([chkgastro]=True,1,0)
    </pre>


    I don't think you intend to pass a value to the TxtOrganCount control. I think you intend to Requery the control instead.

    Me.TxtOrganCount.Requery

  3. #3
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign a value to an Object (2000)

    Ultimately I want the result of the formula passed to a field in the organ support table - ie the result of the formula contained in TxtOrganCount passed to TxtOrgansSupported

    Thanks

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

    Re: Assign a value to an Object (2000)

    Your code passes the value the wrong way.

    You want :
    me.TxtOrgansSupported= me.TxtOrganCount
    (the me is optional but preferred)

    Set the value or OrgansSupported (the stored field) to be equal to the calculated field.

    However standard database practice is not to store calculated values. Instead just recalculate them when you need them.

    As Yes values are stored as -1 and No values as 0, simply add up all the yes/no fields in a query and multiply the result by -1 and you can calculate the number of organs supported in a query easily. So there is no need to store it.
    Regards
    John



  5. #5
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign a value to an Object (2000)

    Thanks - that was a stupid mistake! Thanks for the calculation advice I will try it that way instead.

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

    Re: Assign a value to an Object (2000)

    If you store a calculated value, you need to be sure you update it every time something changes.

    In your form that is not happening, as you only set the value in the on current event. So if you go to a record, then tick a box, the total does not get updated unless you go to another record and come back again.

    You can put code in the after update event of any control that could affect the total, but it is a lot easier just not to store the calculated value.
    (There are exceptions to this of course- but usually only if the calculation needed is long and slow.)
    Regards
    John



  7. #7
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Assign a value to an Object (2000)

    That's true - 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
  •