1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: VBA code for form needed

Discussion in 'Business Applications' started by NEWBIE57, Jan 27, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. NEWBIE57

    NEWBIE57 Thread Starter

    Joined:
    Jan 18, 2011
    Messages:
    65
    I would like some help with some VBA code for my form. Know I could do in the expression builder, but it is extremely tedious.
    This is what I need, have 2 fields, 20' and 40', in these fields they are populated with numbers 1-20, then the calculations are whatever is entered times the 20 and 40. For example: a 2 by 20, would be 2 * 20 = 40, or 3 * 40 = 120, etc. Then these two fields (20' and 40') are added together and put into the field TEU.

    Any help is appreciated.

    Thanks!
     
  2. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    On your second fields afterUpdate event handler put Me.Textbox3 = Me.Textbox1*20 + Me.Textbox2*40

    Change the textbox names to match the control names on your form.
     
  3. NEWBIE57

    NEWBIE57 Thread Starter

    Joined:
    Jan 18, 2011
    Messages:
    65
    Thanks for the help, but having a problem and it's probably the way I changed my fields.

    Here's my code, =[KTIOrders]![TEU]=[KTIOrders]![ContainerSize1]*20+[KTIOrders]![ContainerSize2]*40

    and I get this message:
    The expression AfterUpdate you entered as the event property setting produced the following error.
    The object doesn't contain the Automation object 'KTIOrders'.

    Any help, please.
     
  4. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    Use Me! instead of KTIOrders!
     
  5. NEWBIE57

    NEWBIE57 Thread Starter

    Joined:
    Jan 18, 2011
    Messages:
    65
    Any other ideas? That didn't work.

    =[Me]![TEU]=[Me]![ContainerSize1]*20+[Me]![ContainerSize2]*40

    I'm using 2007, could something with that be a problem?

    Thanks!
     
  6. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    Don't put the = in front of the entire expression.
     
  7. NEWBIE57

    NEWBIE57 Thread Starter

    Joined:
    Jan 18, 2011
    Messages:
    65
    Still not working. Tried putting Forms![Me]![ContainerSize1] and can't get it. Is something different
    with 2007? Some setting or ????

    I'm stumped as to what to do?

    Thanks!
     
  8. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    The code needs to go in the VBA Editor's After Update event procedure for the field not in the Field Property.
    Delete the code, click on the drop down & select Event Procedure and then click on the 3 small dots onthe right hand side.
    Place the VBA code between the 2 lines of code already there.
     
  9. NEWBIE57

    NEWBIE57 Thread Starter

    Joined:
    Jan 18, 2011
    Messages:
    65
    Sorry to assume it was an expression in the db. It worked and I've marked it solved. Thanks for your help!
     
  10. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/977292

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice