Results 1 to 6 of 6
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Odd Subform Behaviour (2003)

    No idea, but there are several problems in your database:

    - You don't have Option Explicit at the top of your modules. As a regular visitor to this forum, you should know that this is very dangerous.
    - You refer to the subform by the wrong name in Testo134_GotFocus; you should use the name it has as a control on the main form.
    - You refer to a nonexistent control txtQt.
    - You twice use Cancel = True in the Form_Load procedure, but Form_Load doesn't have a Cancel argument.

    In the code you propose, PotMedia doesn't return any value.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Odd Subform Behaviour (2003)

    For one thing, you have " ...(),[energia]/[ore_marc]))" in your formula. If [ore-marc] is zero, this could cause a problem. You have to understand that when you use IIF, all parts are evaluated before IIF is really executed; Access doesn't ignore the parts that don't meet the criteria. Try changing formula to to something like this:

    ... [energia] / iif(isnull(ore_marc]),1,ore_marc)...

    This will allow this portion of the equation to be evaluated regardless. And when [ore_marc] is null, we don't really care what it evaluates to, because we won't use it anyway.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Odd Subform Behaviour (2003)

    Many thanks Mark, I've put into practice both your suggestion and Hans'(please see attachment) but still the error message pops upon opening the startup form.
    Any other leads?

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Odd Subform Behaviour (2003)

    Take that function out of the controlsource. Remember, Access will evaluate all the components of the IIF function before it calls IIF, so your function will be called EVERY time, regardless of the situation. Put it in your form's Current event.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Odd Subform Behaviour (2003)

    Thank you so much Hans,
    The attached mdb is virtually identical to the one in question but this one works perfectly without any error messages and I can't make out why! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Can you?

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Odd Subform Behaviour (2003)

    If I substitute the code for the PotMedia function in Module1 of the attached mdb with the following code:

    Function PotMedia()
    MsgBox "Work hours set to zero?", vbOKOnly + vbExclamation, "Warning!"
    End Function

    and the Control Source for the PMedia text box in the MG1Pal subform with:

    =IIf(IsNull([Energia]) Or [energia]=0,Null,IIf([Ore_marc]=0,potmedia(),[energia]/[ore_marc]))

    as soon as I try to open the Palazzolo form, an error message pops up saying that Access has encountered a problem and needs to close.
    How so?

Posting Permissions

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