Results 1 to 7 of 7
  1. #1
    DavidPage is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    4

    dbs.Execute SQL string

    I am trying to execute a INSERT INTO string with dbs.execute to eliminate user from having to select yes for every action query prompt but keep getting Run-time error 3061. Too few parameters. expected 1.

    Can anyone point out what I am doing wrong here? Thanks!


    Private Sub Command25_Click()
    Dim dbs As DAO.Database

    Set dbs = CurrentDb
    If IsNull(EmployeeIdComboBox) = True Then


    MsgBox ("Employee ID is NULL")
    Exit Sub

    Else
    End If

    If Me.Training1 = True Then
    dbs.Execute "INSERT INTO EmployeeTrainings (EmployeeID,TrainingID) VALUES (EmployeeIdComboBox,1)"

    Else
    End If
    'remaining trainings 2 thru 27 will be added here
    End Sub

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    With that small code snippet, try:

    dbs.Execute "INSERT INTO EmployeeTrainings (EmployeeID,TrainingID) VALUES (" & Me.EmployeeIdComboBox & ",1)"

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    jwhite has answered the question, but FYI you could do it in one SQL statement if you have a table with the 27 training ID's in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    DavidPage is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    4
    [ removed ]

  5. #5
    DavidPage is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    jwhite has answered the question, but FYI you could do it in one SQL statement if you have a table with the 27 training ID's in it.
    jwhite - thank you!

    pbaldy - I have a form with a combo box that provides EmployeeId from a table then a series of check boxes each representing trainings. My goal is to select an employee then trainings and append to a employee trainings table with one click. Is it possible to do this in one SQL statement?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I missed that you were testing a checkbox. I don't think that can be done in one go. If you used a listbox:

    http://www.baldyweb.com/MultiselectAppend.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    DavidPage is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    Sorry, I missed that you were testing a checkbox. I don't think that can be done in one go. If you used a listbox:

    http://www.baldyweb.com/MultiselectAppend.htm
    No worries, I didn't state that so my fault. List box would have been a good idea though! Thanks for the help.

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

Similar Threads

  1. Replies: 6
    Last Post: 06-20-2016, 01:29 PM
  2. RunSQL vs. QueryDef.Execute vs. CurrentDB.Execute
    By caubetiep1337 in forum Queries
    Replies: 8
    Last Post: 12-16-2015, 05:35 PM
  3. Execute a module?
    By philip.mccollum in forum Access
    Replies: 1
    Last Post: 07-08-2015, 05:57 AM
  4. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  5. Replies: 10
    Last Post: 02-27-2015, 11:28 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