Results 1 to 3 of 3
  1. #1
    lindaF123 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2017
    Posts
    1

    Populate a file using a query in the background after insert

    This SQL statement works perfectly when I run alone, it requests the input parameter. I want to pass the value in as the value on the form... but when I run it from an after insert event.... telling it to use [Forms]![StudentCourses]![CourseNo] in where statement... it doesnt work.



    The statement won't run at all ... please can you help....


    Private Sub Form_AfterInsert()

    CurrentDb.Execute "INSERT INTO StudentComponents ( ComponentID, courseNo, rectype, StudentID, StuCourseID )" & _
    " SELECT Components.ComponentID, Courses.courseNo, 'C' AS rectype, StudentCourses.StudentID, StudentCourses.StuCourseID" & _
    " FROM (Coursetypes INNER JOIN (Components INNER JOIN Coursecomponents ON Components.ComponentID = Coursecomponents.ComponentID) ON Coursetypes.courseID = Coursecomponents.CourseID) INNER JOIN (Courses INNER JOIN StudentCourses ON Courses.courseNo = StudentCourses.CourseNo) ON Coursetypes.courseID = Courses.courseID" & _
    " WHERE (((Courses.courseNo)=[Forms]![StudentCourses]![CourseNo]));"

    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    it doesnt work.
    isn't very helpful.
    I note that this is your first post. It is always helpful to readers if you describe what you are trying to do in simple English.
    Talk to us as you would to an 8 year old so we get some understanding of the "business". Add details as necessary to clarify any steps you have taken to get to the point you are at. Avoid jargon and acronyms.

    Is this your first database? Can you post a jpg of your tables and relationships?
    Why did you choose the event you are using? etc. etc.

    Welcome and good luck with your project.

  3. #3
    NTC is offline VIP
    Windows 10 Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    I interpret your post in that you are working on a sql statement (which you posted). Have you instead attempted to make this query work using the query design view? If not I would suggest that path first - and then put it into SQL View in order to see the sql statement.

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Replies: 8
    Last Post: 03-19-2014, 10:09 AM
  3. How to run saved query in background
    By shabar in forum Programming
    Replies: 3
    Last Post: 03-03-2013, 11:49 PM
  4. Replies: 3
    Last Post: 07-30-2012, 02:16 PM
  5. insert pdf file on report
    By gschultz in forum Reports
    Replies: 0
    Last Post: 04-01-2010, 07:01 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