Results 1 to 8 of 8
  1. #1
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95

    CurrentRecord Property Syntax


    I'm trying to get a field to calculate based on other fields in a record.

    For example:
    if cboCName1 = "a" then
    txtamt1 = 0.15 * txtpol1
    endif

    This code seems to work but it always calculates bases on the first record in the database rather than the current record. How can I get it to update based on the active record, and for that record only (i.e. not override every record with the current one)?

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well,

    Me.cboCName1

    would refer to the current record. Where exactly do you have that code? Also, make sure your control is bound. If it isn't, the same value will appear in all records in continuous or datasheet view.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    Thanks Paul. I failed to mention in my quick example that I actually used ms.cbocname1. But your other comment seemed to fix my problem. I had started a new module to store the code in, rather than on the module for the form I was refrencing.

    Is there any way to reference the current record on a form but store the code in a seperate module? I only ask because I have a large amount of code and I need to repeat it 5 times. If there is not, it seems to work just fine when stored in the form module. Thanks!

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, from outside the form module

    Forms!FormName.cbocname1

    would refer to whatever record had focus. What are you trying to achieve?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    Calculate a commission based on information entered in a tab control on a user form. The tab control has 5 tabs, so 5 possible commisions for each record. The calculation of the commision is based on 8 different criteria, also stored in the tab control.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, you can put a function in a module and call it as appropriate. The "Forms!" syntax will refer to the record with focus. I'd be more likely to make it a function in the form's module, presuming it will only be called from that form (and since you want to refer to that form, I assume that's the case).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    That is the case, so I will give that a try. Thanks!

    Galt/Taggart 2012?

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo.

    They'd get my vote!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. the property is read only and cannot be set
    By darksniperx in forum Access
    Replies: 16
    Last Post: 11-02-2012, 02:48 PM
  2. access currentRecord
    By fdelval in forum Forms
    Replies: 2
    Last Post: 01-26-2010, 09:37 AM
  3. Can Grow Property
    By chum in forum Reports
    Replies: 3
    Last Post: 01-25-2010, 11:10 AM
  4. Can Grow Property
    By MFeightner in forum Reports
    Replies: 0
    Last Post: 06-24-2009, 11:50 AM
  5. 'On Open' Property
    By emilylu3 in forum Forms
    Replies: 1
    Last Post: 12-08-2005, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums