Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    3

    Arrow Unanswered: Access- Calculated field

    I would need to realize the following thing:
    - I have a fields of 7 char (code a) from table and I need calculate an othe field like this:
    "0000"&right(code a,4) and to concantenate an incremental value (two char) until certain condition.

    Example:

    code a in table = "111abcd"
    new fields = 0000abcd01, 0000abcd02,....0000abcd99.
    I need to use a macro? how?

    Excuse for my english!!!

  2. #2
    Join Date
    Jun 2004
    Location
    Saratoga Springs
    Posts
    24
    I wouldn't do this using a macro per say. Sounds like you need a Do loop. Try something like this (It sounds like you may need to initialize the variables using a recordset):


    ---------

    Public Sub loop_proc()

    code_a = "111abcd"
    var_suf = "1"


    Do Until var_suf = 100

    var_suf = IIf(CDbl(var_suf) < 10, "0" & var_suf, var_suf)

    var_calc_field = "0000" & Right(code_a, 4) & var_suf

    DoCmd.RunSQL "INSERT INTO t1 ( f1 ) SELECT '" & var_calc_field & "';"

    var_suf = var_suf + 1

    Loop


    End Sub

    ----------

    hope this helps

  3. #3
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    3

    Thanks

    Thanks Santiago!

  4. #4
    Join Date
    Jun 2004
    Location
    Saratoga Springs
    Posts
    24
    No problem. If you need help initializing a recordset, beginning an outer loop, and then nesting this loop inside, let me know.

  5. #5
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    3

    more help

    Quote Originally Posted by santiago_jon
    No problem. If you need help initializing a recordset, beginning an outer loop, and then nesting this loop inside, let me know.
    Hi Santiago,
    I would need to code this:
    For each register of a selection consultation (that relates several tables) I need to create
    a new result table containing:
    - each record from consultation
    - generate a new record per each key using the algorithm (alredy sent).

    I will be grateful for you with this.

    Thanks
    Cecilia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •