Results 1 to 12 of 12
  1. #1
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11

    Add activity for each customer

    Hej,

    Table 1: Customer primary key customer Id, other fields: CustomerName and SendInvitation (Yes/no)
    Table 2: Activities primary key activityId, foreign key customerId. Another field: Name, description


    I need to create query that would create new activity for each customer that has SentInvitation = yes

    To make it mo clear:
    Lets say 5 out of 2 customers has SentInvitation field value equal to yes



    CustomerId, CustomerName, SendInvitation
    1, Tom, yes
    2, john, no
    3, Petter, yes
    4, Lisa, no
    5, Alex, no

    What i want is after running a query that only requires me to enter activity description. After running it my Activities table should have 2 new records that should look like that:

    ActivityID, customerId, CustomerName, Description
    autonumber, 1, Tom, "Come visit me"
    autonumber, 3, Petter, "Come visit me"

    Or more in other words

    For each Customer that has sendinvitation = yes Do
    Create new activities record with values:
    ActivityID - auto-generated , customerId = customers.CustomerId , CustomerName = customers.CustomerName , Description - user provided

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This get you started?

    INSERT INTO Activities(...)
    SELECT ...
    FROM Customer
    WHERE SendInvitation = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11
    Hej,

    Thanks for fast replay, but could you give me one full code for the example i gave you.
    I am kinda newbie in access. Still have trouble moving data from one table to another and still struggling with SQL

  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,521
    Did you get this sorted out? If you start a regular query on the customer table and change it to an append query, you should be able to do it all in design view.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11
    Nah, no success yet. I been trying it too

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11
    Ok now i can insert some stuff into activities. But how i define description value? Check google and all examples has either all values selected from other table or hardcoded ( Values(...) )
    I need to select few values from table customers and other values i want to define myself, as description, created, activity type as customer table does not got any info about it.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How do you want to define it? It's easy to refer to a form control to get input for the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11
    ok than i write:

    Insert into T_Customers(name, description)
    From T_Activities ;


    but if activities does not have field named description? how do i define it in this example if description should be taken from Form!MyForm!description

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    SELECT Name, Forms!MyForm.description
    FROM T_Activities
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    nostr4d4m is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    11
    ok i played with it for a while but can find the right order to put it. So my Query looks like this:

    INSERT INTO ActivityHistory ( CompanyId, CompanyName, Description)
    SELECT Companies.CompanyId, Companies.CompanyName
    FROM Companies
    WHERE (((Companies.ResendMail)=True));

    I also need to insert a Description that should be taken from field:
    Forms![InsertActivity]![Comment]

    How do i add it here?

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    SELECT Companies.CompanyId, Companies.CompanyName, Forms![InsertActivity]![Comment]
    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. No activity in last 30 days
    By CMLS in forum Queries
    Replies: 4
    Last Post: 03-18-2011, 11:26 AM
  2. Customer Invoice Strategy
    By ChuckColeman1812 in forum Database Design
    Replies: 2
    Last Post: 03-12-2011, 09:00 AM
  3. Structured Activity
    By Logix in forum Queries
    Replies: 2
    Last Post: 06-10-2010, 06:05 AM
  4. Sorting by customer
    By eibooo in forum Queries
    Replies: 1
    Last Post: 05-25-2010, 12:00 AM
  5. How to Close access form after no activity
    By russ0670 in forum Forms
    Replies: 1
    Last Post: 05-17-2010, 08:17 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