Results 1 to 4 of 4
  1. #1
    mattodeez is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    2

    Create table entries from form for each month selected (One line per month)

    I created a form that has three fields; Name, Project, Month



    The goal of the form is to create a table where if I pick a person and a project, i want to pick what months they are working on a project.

    The table where the info is to be added has only three columns for Name, Project, and Month as well.

    The issue that I'm having is I want to be able to select multiple months and create a unique entry for each month. When I make that list an "extended" or "simple" for MultiSelect, it only creates one entry for the table. If I choose Matt, Project A and January, February, March.... I would need to create three lines in the table, one for each month (with Name and Project the same values in all three lines). I can't figure out how to do this.

    Also, if I have the month list set to "extended" or "Simple" for multiselect, when I choose more than one month, nothing shows up in the table (Table name is "WhatIf").

    Here is my Event Procedure for the click

    Private Sub cmdAdd_Click ()
    'add data to the table

    CurrentDB.Execute "INSERT INTO WhatIf(Name, Project, Month) VALUES ('" & Me.txtname & "','" & Me.txtproject & "','" & Me.listMonth & "')"

    'refresh data in subform

    frmWhatIfSub.Form.Requery

    End Sub

  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
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mattodeez is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    I was not able to figure out how to use your sql in my db. I think I am a little confused since employees is the thing that will have multiple unique values, while in mine, it will be the month that is unique to each line. Also, being a rookie, I don't have all the same things defined at the top of my VBA and not sure how they would translate.

    I attached my project. The form I am working with is "frmWhatIfMain" with the reference tables clrearly labeled.

    Side question...I have one person with an apostraphe in their name and it breaks the system even when I only try to add one month. Any ideas how to fix that?Online Sample1.zip

  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
    I'm using a different method. If you want to stay with yours, you still have to loop the selected items of the listbox and use the value in your SQL inside that loop.

    To get around the apostrophe, use Chr(34) as discussed here:

    http://www.baldyweb.com/BuildSQL.htm
    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. Replies: 5
    Last Post: 10-08-2014, 02:23 PM
  2. Replies: 43
    Last Post: 08-06-2014, 08:21 PM
  3. Replies: 6
    Last Post: 05-05-2014, 10:51 PM
  4. Select Month from previous selected year
    By k0enf0rNL in forum Access
    Replies: 1
    Last Post: 01-15-2014, 12:14 PM
  5. Replies: 4
    Last Post: 05-26-2013, 03:28 PM

Tags for this Thread

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