Results 1 to 3 of 3
  1. #1
    drnurulsyakirin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    4

    Auto fill data based on other data entered in the same form

    Hi All!

    I have a field (field A) in a form that is based on calculation of field B + field C. I wanted another field (field D) to auto enter a description based on field A result.
    E.g.
    if field A > 10, then field D = KK1
    if field A = 8-10, then field D = KK2

    I tried these:
    Private Sub A_AfterUpdate()


    If [A] > 10 Then
    [D] = "KK 1"
    If [A] = 8 - 10 Then
    [D] = "KK 2"


    End Sub

    Tested it but no changes happened to field D...

    Kindly help, thanks!

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Try this (also make sure the fields are formatted as numbers)

    If Me![A] > 10 Then
    Me![D] = "KK 1"
    ElseIf Me![A] >= 8 and Me![A] <= 10 Then
    Me![D] = "KK 2"
    End if

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    When a Field is populated through code, as in

    A = B + C

    most of Field A's events, such as the AfterUpdate event, do not execute! These events will only execute if Field A is physically populated, i.e. through data entered through the keyboard, being pasted into the Control holding the Field, or through it being entered using a scanner.

    If the Value is entered through code, the secondary Field will also have to be populated, through code, at the same time and from the same place in code, something like:

    A = B + C
    If A > 10, Then D = "KK1"
    If A > 7 And A < 11 Then D = "KK2"


    This assumes you're talking about whole numbers only. If you're talking about numbers with fractions, you'll need to adjust the code slightly, but you should get the idea.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 1
    Last Post: 12-21-2011, 02:11 PM
  2. Replies: 0
    Last Post: 09-29-2011, 11:52 AM
  3. Auto fill data (number) between tables
    By juli in forum Access
    Replies: 1
    Last Post: 08-31-2011, 10:41 PM
  4. Replies: 3
    Last Post: 05-26-2011, 12:52 PM
  5. Replies: 6
    Last Post: 04-14-2010, 11:03 AM

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