Results 1 to 24 of 24

Thread: Data Report

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Data Report

    Hi all,

    1) May some pls tell what's wrong with this coding as the system prompt me for a syntax error.
    I'm trying to link my recordset to the data report for printing.

    VB Code:
    1. Private Sub CmdPrint_Click()
    2. Call connectDB
    3. sql = "SELECT distinct * FROM Invoice WHERE Invoice='"
    4. rs.Open sql, cn, adOpenStatic, adLockOptimistic
    5. Set InvoiceReciept.DataSource = rs
    6. InvoiceReciept.Show
    7. End Sub

    2) Can a data report be used to linke differnt fields together? For example, CustID from customer table, Invoiceid from invoice table and CarID from Car Table. Is it possible?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    1) The syntax error is in the Where clause. It is incomplete. The Invoice is = to what...

    Using Distinct * is kind of pointless, as every row will be (should be) unique.

    2) Data Report will display anything in the Recordset that you tell it to display. If you create a recordset from 3 tables, all data in the Selection List is available to the report.
    Last edited by brucevde; Mar 13th, 2006 at 01:28 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Thanks for the reply.

    1) The syntax error is in the Where clause. It is incomplete. The Invoice is = to what...
    Can you pls show an example? is it like InvoiceID "'"?

    2) Data Report will display anything in the Recordset that you tell it to display. If you create a recordset from 3 tables, all data in the Selection List is available to the report.
    I created the recordset in the form. Where shall I write the recordset coding to retrieve the neccessary fields? is under Data Report?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    VB Code:
    1. Private Sub CmdPrint_Click()
    2.    Dim lngInvoiceId As Long
    3.  
    4.    lngInvoiceId = 101010
    5.  
    6.    Call connectDB
    7.  
    8.    sql = "SELECT * FROM Invoices WHERE InvoiceID = " & lngInvoiceId
    9.  
    10.    rs.Open sql, cn, adOpenStatic, adLockOptimistic
    11.  
    12.    Set InvoiceReciept.DataSource = rs
    13.  
    14.    InvoiceReciept.Show
    15. End Sub

    I created the recordset in the form. Where shall I write the recordset coding to retrieve the neccessary fields? is under Data Report?
    Sorry I don't understand you.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    VB Code:
    1. lngInvoiceId = 101010

    Can you pls tell what does the line of code mean?

    If I want to open 3 tables, I should do something like this?

    VB Code:
    1. sql = "SELECT * FROM Customer WHERE CustID = " & lngCustID
    2.  
    3. sql = "SELECT * FROM CarDetails WHERE CarRegNo = " & lngCarRegNo

    Thanks.

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    lngInvoiceId = 101010
    Can you pls tell what does the line of code mean?
    ???? It sets the variable lngInvoiceId equal to 101010 of course. No offense, but if you don't know what a simple assignment statement does, how can you expect to understand other coding.

    If I want to open 3 tables, I should do something like this?
    Do you want to open 3 Recordsets from 3 Tables?
    VB Code:
    1. Dim rsCustomers as ADODB.Recordset
    2. Dim rsCarDetails as ADODB.Recordset
    3.  
    4. sql = "SELECT * FROM Customer WHERE CustID = " & lngCustID
    5. rsCustomers.Open sql, ....
    6.  
    7. sql = "SELECT * FROM CarDetails WHERE CarRegNo = " & lngCarRegNo
    8. rsCarDetails.Open sql,...

    However, the Data Report can only use 1 Recordset at a time, so you would need to Join the tables on a field that is common to both.

    VB Code:
    1. Dim rsBoth as ADODB.Recordset
    2. sql = "Select * From Customer Inner Join CarDetails On Customer.CustID = CarDetails.CustId Where Customer.CustId = " & lngCustId & " and CarDetails.CarRegNo = " & lngCarRegNo
    3. rsBoth.Open sql,...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Sorry for that noob question.

    I was actually asking if it's possible for user to print as shown on the picture attached. For example, the user is browsing the records and he wants to print invoice 142. Do he have to enter 142 or the program will auto direct him to Datareport.

    VB Code:
    1. Dim rsBoth as ADODB.Recordset
    2. sql = "Select * From Customer Inner Join CarDetails On Customer.CustID = CarDetails.CustId Where Customer.CustId = " & lngCustId & " and CarDetails.CarRegNo = " & lngCarRegNo
    3. rsBoth.Open sql,...

    For what I understand, JOINSQL is used only when you are joining identical fields. However, in my case, I have to use recordset to link First Name, Address etc also.

    Is possible do that?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    opps, here is the picture.
    Attached Images Attached Images  

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Pls offer all your suggestion, I will be greatly appreciated.

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    For what I understand, JOINSQL is used only when you are joining identical fields. However, in my case, I have to use recordset to link First Name, Address etc also.

    Is possible do that?
    Without knowing your database schema it would be impossible to answer that question.

    For example, the user is browsing the records and he wants to print invoice 142. Do he have to enter 142 or the program will auto direct him to Datareport.
    As long as an Invoice number is already loaded into the Textbox, the code behind the Print button can do everything neccessary to run the Data Report.

    VB Code:
    1. Private Sub CmdPrint_Click()
    2.    Dim rs as ADODB.Recordset
    3.  
    4.    Call connectDB
    5.  
    6.    sql = "SELECT * FROM Invoices WHERE InvoiceID = " & txtInvoiceNo.Text
    7.  
    8.    Set rs = New ADODB.Recordset
    9.    rs.CursorLocation = adUseClient
    10.    rs.Open sql, cn, adOpenStatic, adLockReadOnly
    11.    Set rs.ActiveConnection = Nothing
    12.  
    13.    Set InvoiceReciept.DataSource = rs
    14.  
    15.    InvoiceReciept.Show
    16.    Set rs = Nothing
    17. End Sub

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Thanks for that reply.

    But can I also use sql to open customer table simultaneously with Invoice table?

  12. #12
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: Data Report

    yes if it is an action query

    update and insert

    if you want to oen them simultaneously declare them with different recordset
    dim rs1 as adodb.recordset,rs2 as recordset
    set rs1= new adodb.recorset
    rs1.open,"select * from customer",cn,adopenstatic
    set rs2= new adodb.recorset
    rs2.open,"select * from invoice",cn,adopenstatic

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Data Report

    Moved to reporting section

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    What are the possiblity errors when the system prompt that Report sections do not match datasource.

    Below is my sub module.

    VB Code:
    1. Private Sub cmdPrint_Click()
    2.       Unload Me
    3.       Call connectDB
    4.       rs.Open "SELECT * FROM Invoice", cn, adOpenStatic, adLockOptimistic
    5.       Set InvoiceReciept.DataSource = rs
    6.       InvoiceReciept.Show
    7. End Sub

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Hi,

    Anyone?

  16. #16
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    Did you add a Group to your report? You can only use groups if you have a "hierarchical" recordset.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Pardon me, what do you mean by group?

    A group of attributes?

  18. #18
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    No. I mean did you insert Group Header and Footer sections? If yes and the recordset is not a hierarchical recordset you will get the error "Report Sections do not match Datasource".

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Thanks for that reply.

    Somehow, I recreate a new datareport and that error went away.
    However, when I try to open 2 connectionsetp, there is an runtime error[Type Mismatch] on the lngCustID = Cbo_Cust. Why is this so?

    VB Code:
    1. Private Sub CmdPrint_Click()
    2.    Dim lngInvoiceId, lngCustID As Long
    3.    Dim rsCustomers As New adodb.Recordset
    4.  
    5.  
    6.    lngInvoiceId = Txt_NoOfInv
    7.    
    8.    lngCustID = Cbo_Cust 'error source
    9.    
    10.    Call connectDB
    11.  
    12.    sql = "SELECT * FROM Invoice WHERE InvoiceID = " & lngInvoiceId
    13.    rs.Open sql, cn, adOpenStatic, adLockOptimistic
    14.    
    15.    sql = "SELECT * FROM Customer WHERE CustID = " & lngCustID
    16.    rsCustomers.Open sql, cn, adOpenStatic, adLockOptimistic
    17.    
    18.  
    19.    Set Reciept.DataSource = rs
    20.  
    21.    Reciept.Show
    22. End Sub

  20. #20
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    The Type Mismatch error probably occurs because Cbo_Cust contains character data (perhaps the Customer Name) and you are trying to convert it to Numeric.

    Here is a sample report using Hierarchical Recordset. It uses the Northwind database, just change the path in the db.open statement.
    Attached Files Attached Files

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Thanks for the attached files, but it seem alittle complicated to me. I think I need more guidance on that. My porject will be completed after this datareport. Hope you can help.

    For example, I need to display the InvoiceID, DateRent, DateRetun from the Invoice table.

    CustID, CustFname, CustLname from the customer table

    CArRegNo No, Car Model and Cartype from cardetails table.


    How may I link them together to display in the Date report format.
    Attached Images Attached Images  

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    VB Code:
    1. strSQL = "Shape {Select Customer.CustId, CustFname, CustLname From Customer} " & _
    2.              "APPEND (" & _
    3.                       "(Shape {Select CustId, invoiceId, RentDate From invoice} " & _
    4.                         "APPEND ({Select invoiceID, ([Invoice].DateReturn - DateRent) As TotalDays "

    Is there any wrong with this syntax as I want to link customer table and invoice table together as shown in the diagram above.

  23. #23
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Report

    You need to include the Relate commands (which are like Inner Joins).
    Can you let me know the layout of the report? The layout will dictact how many Child recordsets will exist in the Hierarchy.

    The following assumes you want one group (Customer) and one Child (invoice and cardetail).

    VB Code:
    1. strSQL = "Shape {Select Customer.CustId, CustFname, CustLname From Customer} " & _
    2.     "APPEND ({Select I.CustId, I.invoiceId, I.RentDate, I.CarRegNo, CD.CarModel From invoice " & _
    3.              "Inner Join CarDetails CD On CD.CustId = I.CustId And CD.CarRegNo = Invoice.CarRegNo} "& _
    4.    " Relate CustId to CustId)  As InvoiceCarDetails "

    To use the fields from the Child recordset, you must set the DataMember property for controls on your report to InvoiceCarDetails.

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    365

    Re: Data Report

    Thanks for offering to help.

    Hereby attached my DR to you.

    Btw, I have set MDI child = true for my datareport, hope it will not affect the outcome.
    Attached Files Attached Files
    Last edited by macky^^; Mar 18th, 2006 at 01:17 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
  •  



Click Here to Expand Forum to Full Width