General discussion

  • Creator
    Topic
  • #2178816

    AccessForm:AfterUpdateEvent code writing

    Locked

    by jpadilla ·

    FieldName “MainDTCode” is set for DATA TYPE=text and limits the input range (1-999). I am currently utilizing 1-165 of the range.
    Each one the those entries requires a corresponding “Code,” limited to only: MTN,PRO,OTH,SET and RAW.
    How do I write the code so that when the user iputs a number into the Form\FieldName\ “MainDTCode”, it auto fills the FieldName\”Code” with one of the five alpha codes?
    e.g.
    If MainDTCode=”54″ then Code=”CHG”
    End If
    Is this correct? Please be specific.

All Comments

  • Author
    Replies
    • #3082558

      Reply To: AccessForm:AfterUpdateEvent code writing

      by jpadilla ·

      In reply to AccessForm:AfterUpdateEvent code writing

      Point value changed by question poster.

    • #3094436

      Reply To: AccessForm:AfterUpdateEvent code writing

      by dryflies ·

      In reply to AccessForm:AfterUpdateEvent code writing

      Load the form that contains the field you wish to evaluate. I am not sure about your use of a text field and then limiting the input to a range of numeric values. this is problematic as numbers in a text field sort differently than numbers in a numerical field. eg in a text field, 002 sorts before 1. in a numeric field 002 sorts after one. this is important when you apply an IIF to your value.

      Your selection of the after update event is correct. I am going on the assumption that you go to pure numerics to coreect your sort situation.
      open a new macro in design view.
      right click on its title bar and check “conditions” to make the conditions field visible. click in the conditions field, then enter “[MainDTCode] = 54” leave off the quotes when you type.
      in the action field, enter “SetValue” down below there will be an “item” textbox and an “expression” text box in the item text box enter [Code] and in the expression box put “CHG”
      you can also enter ranges in the conditions field by using ([MainDTCode] < 99) And ([MainDTCode] > 50)
      you may also choose to use the fully qualified names of the fields to reduce ambiguity eg. “[Forms]![Member Types]![MemberTypeID]”
      you can also do this in VB but a macro will cause you fewer headaches.
      please rate my answer.

    • #3094435

      Reply To: AccessForm:AfterUpdateEvent code writing

      by dryflies ·

      In reply to AccessForm:AfterUpdateEvent code writing

      Load the form that contains the field you wish to evaluate. I am not sure about your use of a text field and then limiting the input to a range of numeric values. this is problematic as numbers in a text field sort differently than numbers in a numerical field. eg in a text field, 002 sorts before 1. in a numeric field 002 sorts after one. this is important when you apply an IIF to your value.

      Your selection of the after update event is correct. I am going on the assumption that you go to pure numerics to coreect your sort situation.
      open a new macro in design view.
      right click on its title bar and check “conditions” to make the conditions field visible. click in the conditions field, then enter “[MainDTCode] = 54” leave off the quotes when you type.
      in the action field, enter “SetValue” down below there will be an “item” textbox and an “expression” text box in the item text box enter [Code] and in the expression box put “CHG”
      you can also enter ranges in the conditions field by using ([MainDTCode] < 99) And ([MainDTCode] > 50)
      you may also choose to use the fully qualified names of the fields to reduce ambiguity eg. “[Forms]![Member Types]![MemberTypeID]”
      you can also do this in VB but a macro will cause you fewer headaches.
      please rate my answer.

    • #3095601

      Reply To: AccessForm:AfterUpdateEvent code writing

      by jpadilla ·

      In reply to AccessForm:AfterUpdateEvent code writing

      This question was closed by the author

Viewing 3 reply threads