Results 1 to 7 of 7

Thread: [RESOLVED] INSERT INTO Report

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    Ontario
    Posts
    114

    Resolved [RESOLVED] INSERT INTO Report

    Really could use some help on this one...
    Is it possible to INSERT data into a report on microsoft access?

    I have the report already created and data gets moved into the table that links with the report and it seems to show the data, but I would like to add two more pieces of data to it but it seems not to be working.

    I would like to add the min and max time to the report which is taken from another table called MainDataLog.
    VB Code:
    1. Connect.Execute "INSERT INTO Shift_Totals (" & _
    2. "MaxTime ," & _
    3. "MinTime  ," & _
    4. "Select    ," & _
    5. "MIN([TIME]) , " & _
    6. "MAX([TIME]), " & _
    7. "FROM MainDataLog"
    The error I am getting is syntax error in insert into statement

  2. #2
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    308

    Re: INSERT INTO Report

    Quote Originally Posted by Mcritt
    Really could use some help on this one...
    Is it possible to INSERT data into a report on microsoft access?

    I have the report already created and data gets moved into the table that links with the report and it seems to show the data, but I would like to add two more pieces of data to it but it seems not to be working.

    I would like to add the min and max time to the report which is taken from another table called MainDataLog.
    VB Code:
    1. Connect.Execute "INSERT INTO Shift_Totals (" & _
    2. "MaxTime ," & _
    3. "MinTime  ," & _
    4. "Select    ," & _
    5. "MIN([TIME]) , " & _
    6. "MAX([TIME]), " & _
    7. "FROM MainDataLog"
    The error I am getting is syntax error in insert into statement
    This is a table Yes ??

    You are missing a closing bracket on the SQL String
    Also your Min & Max were the wrong way around:
    Should read something like:

    Code:
    Connect.Execute "INSERT INTO Shift_Totals (" & _
    "MinTime," & _
    "MaxTime)" & _
    "Select " & _
    "MIN([TIME]) , " & _
    "MAX([TIME]) " & _
    "FROM MainDataLog"

    Chubby.

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: INSERT INTO Report

    You don't need an INSERT statement.

    For you MIN date (same procedure for your MAX date)
    1/ Add a textbox to the report
    2/ Change the "Control Source" for the TextBox to
    Code:
    SELECT MIN([TIME]) FROM MainDataLog
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    Ontario
    Posts
    114

    Re: INSERT INTO Report

    DKenny, I tried what you said and it gives me syntax error (missing operator)in query expression 'First([Select MIN([Time])From MainDataLog]). Not sure where the 'first' came from because I never typed it in, and it seems to be putting extra square brackets around everything.
    I typed it in like this Select MIN ([Time]) FROM MainDataLog

    Unfortuatly chubby method won't work beacuse I have data there and if I add that code in, it places the min and max time in a seperate column(like it should) but on another row at the buttom of the table so the dates always come p with nothing in them...
    Last edited by Mcritt; Mar 30th, 2006 at 12:20 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    Ontario
    Posts
    114

    Re: INSERT INTO Report

    anyone else have a suggestion for me? I could really use some help.... I still seem to be having trouble building the expression in access

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: INSERT INTO Report

    God I hate Access.
    There doesn't seem to be any way to achieve this with TextBoxes. It can be done, however with Lables.

    In this example I added to 2 labels and put juck data in their captions. I called them "lblMinPlaceholder" and "lblMaxPlaceholder" respectively.
    Then in the _Open event code for the report I put the following code.

    I hope that this will give you what you need....

    VB Code:
    1. Private Sub Report_Open(Cancel As Integer)
    2. Dim rsDate As ADODB.Recordset
    3.  
    4.     Set rsDate = New ADODB.Recordset
    5.    
    6.     rsDate.Open "Select Min([Time]) from MainDataLog", CurrentProject.Connection
    7.        
    8.     Me.lblMinPlaceholder.Caption = rsDate.Fields(0).Value
    9.    
    10.     rsDate.Close
    11.    
    12.     rsDate.Open "Select Max([Time]) from MainDataLog", CurrentProject.Connection
    13.    
    14.     Me.lblMaxPlaceHolder.Caption = rsDate.Fields(0).Value
    15.    
    16.     rsDate.Close
    17.     Set rsDate = Nothing
    18. End Sub
    Attached Files Attached Files
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    Ontario
    Posts
    114

    Re: [RESOLVED] INSERT INTO Report

    Thanks for all the help...
    I added the code posted the access report vba, didn't work at first but went to tools references and enabled activeX... works like a charm....thanks again

Posting Permissions

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



Click Here to Expand Forum to Full Width