Results 1 to 4 of 4
  1. #1
    Mohibullah is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    25

    Code only updating after physical click

    Hi everyone,



    So I coded IF statements to attach values to particular text entries, for example

    Private Sub txtCarType_Enter()

    If txtCarType = "Sedan" Then
    txtCT = 1

    ElseIf txtCarType = "SUV" Then
    txtCT = 6.4

    ElseIf txtCarType = "Truck" Then
    txtCT = 29.2

    ElseIf txtCarType = "Full Sized Truck" Then
    txtCT = 50

    End If

    End Sub


    Private Sub txtIncreasedCollisionRisk_Enter()

    If txtIncreasedCollisionRisk = "None" Then
    txtICR = 0

    ElseIf txtIncreasedCollisionRisk = "Outage in 1 year" Then
    txtICR = 1

    ElseIf txtIncreasedCollisionRisk = "1 Outage in next 2 years" Then
    txtICR = 0.2

    ElseIf txtIncreasedCollisionRisk = "1 Outage in next 10 years" Then
    txtICR = 0.1

    End If

    End Sub


    I did this so the textboxes would provide a numerical value in relation to other textboxes text entries, which are all used to make a prioritization number. I made a field for the prioritization number, which is a calculated field, which takes the respective fields that are linked to each textbox that have had IF statements made for them, and adds/subtracts/divides them accordingly, for example:

    [Car Type] - [Collision Risk]

    Now the actual numbers for the calculation appear in the txtICR and txtCT textboxes, which are linked to fields that separate from the text fields, however the text fields need to be entered with text, then clicked, in order for the number text box to populate, which can then populate the prioritization textbox.


    I want the textboxes to create this calculation simply after the text entries are entered, with no clicking necessary. I tried changing the textbox code to Click, Change, etc., but it doesn't make any differences.

    Any help with this complicated calculation would be much appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    Instead of building lots of IFs, put these values in a lookup table.
    the query will retrieve the conversion instead of code.

  3. #3
    Mohibullah is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    25
    Quote Originally Posted by ranman256 View Post
    Instead of building lots of IFs, put these values in a lookup table.
    the query will retrieve the conversion instead of code.
    Given what I've shown you in my style of IFs, could you show me and example of how to put these in a lookup table?

    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    FYI, the appropriate event would be the after update event. The enter event fires when focus "enters" the textbox, not when you hit "Enter". I agree with putting the values in a table though.
    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. Skip section of code on button click
    By NovoRapid in forum Modules
    Replies: 2
    Last Post: 02-05-2015, 02:43 PM
  2. Replies: 7
    Last Post: 12-16-2013, 11:12 AM
  3. Database Design - Physical / Postal Address Issue
    By PeterPeterson in forum Access
    Replies: 3
    Last Post: 09-27-2012, 06:27 AM
  4. Replies: 3
    Last Post: 04-10-2012, 04:42 PM
  5. Each time I click run different code
    By Dominaz in forum Access
    Replies: 3
    Last Post: 11-14-2011, 08:44 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