Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008

    Unanswered: Append Query Run from form

    I am trying to use a commandbutton to run two actions:

    1. run append query based on paramaters on form
    2. go to create new record.

    Here is my code:

    Private Sub CmdNew_Click()
    'Run Append Query

    DoCmd.OpenQuery "qryAppendUnitstoStudentClass"
    DoCmd.Close acDefault, "qryAppendUnitstoStudentClass"

    'Begin New Record
    DoCmd.GoToRecord , , acNewRec

    End Sub

    I don't get any error messages, what I get is '0' rows appended to my table.

    I found somewhere on the internet a comment that OpenQuery won't work on an append query and tried the following line of code:

    CurrentDb.Execute ("qryAppendUnitstoStudentClass"), dbFailOnError

    When I run the code I get an error message "Run-time error '3061' Too few paramaters expected 2"

    Here is my query:
    INSERT INTO tblCompetency ( StudentClassID, SubjectID, UnitID, ElementID, PerformanceID )
    SELECT tblStudentsClasses.StudentClassID, tblClasses.SubjectID, tblUnit.UnitID, tblElements.ElementID, tblPerformanceCriteria.PerformanceID
    FROM tblClasses INNER JOIN tblStudentsClasses ON tblClasses.ClassID = tblStudentsClasses.ClassID, tblUnit INNER JOIN (tblElements INNER JOIN tblPerformanceCriteria ON tblElements.ElementID = tblPerformanceCriteria.ElementID) ON tblUnit.UnitID = tblElements.UnitID
    WHERE (((tblStudentsClasses.StudentClassID)=[forms]![frmAddStudentstoClass]![StudentClassID]) AND ((tblClasses.SubjectID)=[forms]![frmClasses]![ClassID]));

    Any suggestions welcomed, I'm going nuts trying to solve this.


  2. #2
    Join Date
    Jun 2007
    Maitland NSW,Australia

    You can use DoCmd.OpenQuery "qryAppendUnitstoStudentClass"
    to run an append query.

    Create a select query to check that you have the required data then change the select query to an append query to add the data to the table.

  3. #3
    Join Date
    Nov 2008
    Yes, thanks, I have solved this problem.

    I took a new approach, my problem was not with the code, but the fact that the form I was using was open in 'Add' mode. The code couldn't find the data because the record hadn't been saved yet.


Posting Permissions

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