Results 1 to 5 of 5
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    error when trying to append the tempTable

    Hello to all friends,


    I'm trying to write a code so that it gets the data from a query (QryPrint) and then to put them in a temporary table (tblWeekData) so that I can present them in a report.


    I have written the following code but the vba gives error constantly on DietID which is a field (into query). I would appreciate if some friend from the forum could help me

    Sub OpenReport()
    Dim i As Integer, x As Integer, tmpMax As Integer, TheFood As String
    Dim rsSource As DAO.Recordset
    Dim rsTarget As DAO.Recordset
    CurrentDb.Execute "DELETE * FROM tblWeekPlan"
    Set rsTarget = CurrentDb.OpenRecordset("tblWeekPlan", dbOpenDynaset)
    For i = 1 To 25
    rsTarget.AddNew
    rsTarget.Fields("iNum") = i
    rsTarget.Update
    Next


    For i = 1 To 7


    Set rsSource = CurrentDb.OpenRecordset("SELECT QryPrint.* FROM QryPrint WHEREDietCode =" & [DietID] & " AND DayCode =" & i & " ORDER BY [Type of Meal]")
    If rsSource.RecordCount Then
    If tmpMax < rsSource.RecordCount Then tmpMax = rsSource.RecordCount
    rsSource.MoveFirst
    rsTarget.MoveFirst
    For x = 1 To rsSource.RecordCount
    rsTarget.FindFirst "iNum=" & x
    rsTarget.Edit
    TheFood = Nz(DLookup("FoodName", "tblFoodAnalysis", "[FoodID]=" & rsSource.Fields("Food")))
    rsTarget.Fields("MealCat") = Nz(rsSource.Fields("[Type of Meal]"), "")
    rsTarget.Fields("d" & i) = TheFood & " - " & Nz(rsSource.Fields("Conc"), "")
    rsTarget.Update
    rsSource.MoveNext
    Next
    End If
    Next
    CurrentDb.Execute "DELETE * FROM tblWeekPlan WHERE iNum > " & tmpMax

  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,652
    What error do you get? Where is DietID coming from (or supposed to be coming from)? Have you added a space between WHERE and DietCode? That's the exact spelling of the field name in the query?

    By the way, is there a reason you can't just base the report on the query?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hi pbaldy,

    Thanks for your reply. The error is : "Cannot find the DietCode" but in the query there is this field...

    Really don't know....

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You are not answering all the questions Paul is asking. Also, I do not believe I have ever encountered that error message.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Along with the other questions, see if this helps find the problem:

    http://www.baldyweb.com/ImmediateWindow.htm

    what is the SQL of qryPrint?
    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. append error
    By slimjen in forum Forms
    Replies: 3
    Last Post: 04-30-2013, 09:31 AM
  2. Error Handling & Append Queries
    By DarkWolff in forum Programming
    Replies: 11
    Last Post: 04-20-2012, 03:05 PM
  3. append query error
    By kallm in forum Programming
    Replies: 0
    Last Post: 02-26-2012, 09:35 AM
  4. Append Query Error
    By lupis in forum Queries
    Replies: 1
    Last Post: 06-18-2010, 02:10 AM
  5. append query error
    By shashigk in forum Queries
    Replies: 2
    Last Post: 09-22-2009, 07: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