Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2019
    Posts
    1,103

    VBA routine to insert updated values into new table

    Good morning:



    I need some assistance with creating a) a VBA routine or b) an UPDATE query OR b) a MAKE TABLE query. Attached DB contains table [T_SAMPLE_DATA] including 15 *sample* (random) records.

    Additional background:
    - FIELD_1 will contain distinct string values for each record.
    - FIELD_2 will only be partially populated for each record.

    Update/Make Table Process:
    - I need to end up with a new/updated table "T_TEST" where...
    a. All values in FIELD_1 = "Value" AND...
    b. All non-null values in FIELD_2 = "NotNull" AND...
    c. All null values in FIELD_2 = "Null"

    Please see table [T_TEST_WhatItNeedsToLookLike] illustrating how [T_TEST] should look like once created from [T_SAMPLE_DATA].

    My question:
    - What does the VBA (or query) look like to accomplish this task?
    Attached Thumbnails Attached Thumbnails Example.png  
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2019
    Posts
    1,103
    Below works just fine in VBA routine:

    Code:
    UPDATE T_NEW SET T_NEW.FIELD_1 = 'Value';
    UPDATE T_NEW SET T_NEW.FIELD_2 = 'NotNull' WHERE (((T_NEW.FIELD_2) Is Not Null));
    UPDATE T_NEW SET T_NEW.FIELD_2 = 'Null' WHERE (((T_NEW.FIELD_2) Is Null));

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    TRY

    Code:
    SELECT  "Value" as Field_1
    ,iif ( T_SAMPLE_DATA.field_2 is null,"Null","NotNull") as field_2
    INTO NewTable_Tom
    FROM T_SAMPLE_DATA;

  4. #4
    Join Date
    Feb 2019
    Posts
    1,103
    Orange -- wow, that's a nice variation. Thank you for assisting w/ streamlining the process.

    Cheers,
    Tom

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Replies: 44
    Last Post: 04-05-2021, 07:11 AM
  2. Replies: 1
    Last Post: 03-17-2014, 02:13 AM
  3. Insert Into Query With Table data and values
    By WickidWe in forum Queries
    Replies: 1
    Last Post: 01-05-2014, 06:41 PM
  4. Replies: 2
    Last Post: 02-04-2012, 01:48 PM
  5. Replies: 0
    Last Post: 10-24-2010, 02:27 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