Results 1 to 6 of 6
  1. #1
    Fish218 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    68

    After Update Event with power function

    I am working on error-proofing data entry into the database I created for fish data. I am trying to figure out how I can prevent keystroke errors on length and weight data. I plan to use an after update event in the weight field. I can use existing data to figure out the relationship between length and weight for each species (usually a power function e.g. y = 0.1111x^3.0701 for a particular species I work with). What I don't know how to do is write the code to compare the weight typed in to a range of weights expected for a fish of a certain length.



    Given the above equation, a fish that is 16" long should weigh 552 grams. I need the code to say, if the fish is 16 inches long the weight should be 552 grams + or - 25%. Any suggestions?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Options:

    1. a table with fields for length, min weight, max weight, then use DLookup function:

    If IsNull(DLookup("length","tablename","length=" & Me.Length & " AND " & Me.Weight & " BETWEEN MaxWt AND MinWt") Then
    MsgBox "Weight entered is outside normal range. Is it correct?"
    End If

    2. a table with fields for length and average weight, then use DLookup function:

    Dim AvgWt As Double
    AvgWt = DLookup("AvgWt","tablename","Length=" & Me.Length)
    If Me.Weight < AvgWt - 0.25 * AvgWt Or Me.Weight > AvgWt + 0.25 * AvgWt Then
    MsgBox "Weight entered is outside normal range. Is it correct?"
    End If

    3. No table and calculate the AvgWt

    Dim AvgWt As Double
    AvgWt = some formula here
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Fish218 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    68
    My data entry form (and corresponding table) have field for species, length, weight, etc. Is it possible to make option #1 species specific?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, that would be another criteria in the DLookup WHERE CONDITION argument. Is species a text field? If so, need apostrophe delimiters.

    "species='" & Me.Species & "' AND length=" & Me.Length & " AND " & Me.Weight & " BETWEEN MaxWt AND MinWt"

    If the table has only weight, not MaxWt and MinWt, then I think you need option 2
    AvgWt = DLookup("weight","tablename",""species='" & Me.Species & "' AND length=" & Me.Length)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Fish218 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    68
    I like the Min/Max feature of Option #1. I could create a query that has species, min weight, and max weight, correct?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You can create query with min and max weights with any of the options.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-08-2012, 01:34 PM
  2. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  3. Before Update Event Help
    By bklewis in forum Access
    Replies: 8
    Last Post: 03-25-2012, 03:58 PM
  4. Replies: 1
    Last Post: 08-15-2011, 03:20 PM
  5. Replies: 2
    Last Post: 07-19-2011, 04: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