Results 1 to 14 of 14

Thread: Add table with grid in datareport

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    49

    Add table with grid in datareport

    Dear friends,
    I have developed application for patient data management. I have option for patient diacharge card. I have used access as database and datareport to print discharge card. I wish to add a table in patient's pathology report column and want to print the same in datareport. Is it possible any way? If I copy table from word or excel and place it in userform textbox only datawithout table get paste. Please guide me. Below is the code of saving discharge card and print it.


    Save button command for discharge card
    Private Sub CommandButton10_Click()

    If TextBox25.Text = "" Then
    MsgBox "IPD no is blank"
    Exit Sub
    End If

    On Error GoTo ErrorHandler


    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset

    Dim qry As String, i As Integer
    Dim n As Long




    cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "\\192.168.1.120\d\d\Database.accdb"

    qry = "SELECT * FROM IPD WHERE [IP No] = '" + Me.TextBox25.Text + "'"


    rst.Open qry, cnn, adOpenKeyset, adLockOptimistic



    rst.Fields("History").Value = TextBox31.Value
    rst.Fields("Examination").Value = TextBox32.Value
    rst.Fields("Hospital course").Value = TextBox33.Value
    rst.Fields("Investigations").Value = TextBox34.Value//here I want to place table
    rst.Fields("Operation").Value = TextBox35.Value
    rst.Fields("OTnote").Value = TextBox44.Value
    rst.Fields("Treatment").Value = TextBox36.Value
    rst.Fields("Advise").Value = TextBox37.Value

    rst.Fields("Condition").Value = TextBox38.Value
    rst.Fields("Diagnosis").Value = TextBox39.Value

    rst.Fields("DC Username").Value = Label31.Caption
    rst.Fields("DC Date&time").Value = Now()


    rst.Update
    MsgBox "Discharge card saved successfully for " & TextBox26.Text

    rst.Close
    cnn.Close







    Exit Sub
    ErrorHandler:

    MsgBox "Oops, an error has occured." & vbCrLf & vbCrLf & "Error Code : " & Err.Number & " , " & Err.Description, vbCritical, "Error"
    Exit Sub

    End Sub

    commandbutton to print discharge card
    Sub Pdischarge()
    On Error GoTo ErrorHandler





    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset

    Dim qry As String, i As Integer
    Dim n As Long




    cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "\\192.168.1.120\d\d\Database.accdb"

    qry = "SELECT * FROM IPD WHERE [IP No] = '" + Me.TextBox25.Text + "'"


    rst.Open qry, cnn, adOpenKeyset, adLockOptimistic


    With DataReport3
    Set .DataSource = rst
    With .Sections("Section1").Controls



    .Item("Name").Caption = "Patient Name: " & rst.Fields("Name").Value
    .Item("RegNo").Caption = "Reg No.: " & rst.Fields("Reg No").Value
    .Item("Age").Caption = "Age/Sex: " & rst.Fields("Age").Value & "/" & rst.Fields("Sex").Value
    .Item("DOA").Caption = "Date of admission: " & Format(rst.Fields("Admitdate").Value, "dd/mm/yyyy")
    .Item("IPDNo").Caption = "IPD No.: " & rst.Fields("Ip No").Value
    .Item("DOD").Caption = "Date of discharge: " & Format(rst.Fields("Dischargedate").Value, "dd/mm/yyyy")
    .Item("Diagnosis").Caption = rst.Fields("Diagnosis").Value
    .Item("History").Caption = rst.Fields("History").Value
    .Item("Examination").Caption = rst.Fields("Examination").Value
    .Item("Hospital").Caption = rst.Fields("Hospital course").Value
    .Item("Investigation").Caption = rst.Fields("Investigations").Value//I wish to print table with grid here

    .Item("Treatment").Caption = rst.Fields("Treatment").Value
    .Item("Advise").Caption = rst.Fields("Advise").Value
    .Item("Condition").Caption = rst.Fields("Condition").Value
    If rst.Fields("Operation").Value <> "" Then

    .Item("Operation").Caption = rst.Fields("Operation").Value
    .Item("Line9").Visible = True
    .Item("Label10").Visible = True
    .Item("Label22").Visible = True
    Else
    .Item("Operation").Caption = ""
    .Item("Line9").Visible = False
    .Item("Label10").Visible = False
    .Item("Label22").Visible = False
    End If




    End With

    .Show
    .WindowState = 0
    End With









    Exit Sub
    ErrorHandler:

    MsgBox "Oops, an error has occured." & vbCrLf & vbCrLf & "Error Code : " & Err.Number & " , " & Err.Description, vbCritical, "Error"
    Exit Sub


    End Sub

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Add table with grid in datareport

    This looks like VBA code which belongs here: https://www.vbforums.com/forumdispla...ce-Development. As to your question:
    https://chandoo.org/forum/threads/ms...-toolbox.9042/. And use code tags to enclose code you post here. You can add these tags by clicking on the "#" button in the toolbar above the message you're about to post.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    49

    Re: Add table with grid in datareport

    Dear friends,
    I have developed application for patient data management. I have option for patient diacharge card. I have used access as database and datareport to print discharge card. I wish to add a table in patient's pathology report column and want to print the same in datareport. Is it possible any way? If I copy table from word or excel and place it in userform textbox only datawithout table get paste. Please guide me. Below is the code of saving discharge card and print it.


    Save button command for discharge card

    Code:
    Private Sub CommandButton10_Click()
    
    If TextBox25.Text = "" Then
    MsgBox "IPD no is blank"
    Exit Sub
    End If
    
    On Error GoTo ErrorHandler
    
    
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    
    Dim qry As String, i As Integer
    Dim n As Long
    
    
    
    
    cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "\\192.168.1.120\d\d\Database.accdb"
    
    qry = "SELECT * FROM IPD WHERE [IP No] = '" + Me.TextBox25.Text + "'"
    
    
    rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
    
    
    
    rst.Fields("History").Value = TextBox31.Value
    rst.Fields("Examination").Value = TextBox32.Value
    rst.Fields("Hospital course").Value = TextBox33.Value
    rst.Fields("Investigations").Value = TextBox34.Value//here I want to place table
    rst.Fields("Operation").Value = TextBox35.Value
    rst.Fields("OTnote").Value = TextBox44.Value
    rst.Fields("Treatment").Value = TextBox36.Value
    rst.Fields("Advise").Value = TextBox37.Value
    
    rst.Fields("Condition").Value = TextBox38.Value
    rst.Fields("Diagnosis").Value = TextBox39.Value
    
    rst.Fields("DC Username").Value = Label31.Caption
    rst.Fields("DC Date&time").Value = Now()
    
    
    rst.Update
    MsgBox "Discharge card saved successfully for " & TextBox26.Text
    
    rst.Close
    cnn.Close
    
    
    
    
    
    
    
    Exit Sub
    ErrorHandler:
    
    MsgBox "Oops, an error has occured." & vbCrLf & vbCrLf & "Error Code : " & Err.Number & " , " & Err.Description, vbCritical, "Error"
    Exit Sub
    
    End Sub
    commandbutton to print discharge card
    Code:
    Sub Pdischarge()
    On Error GoTo ErrorHandler
    
    
    
    
    
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    
    Dim qry As String, i As Integer
    Dim n As Long
    
    
    
    
    cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "\\192.168.1.120\d\d\Database.accdb"
    
    qry = "SELECT * FROM IPD WHERE [IP No] = '" + Me.TextBox25.Text + "'"
    
    
    rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
    
    
    With DataReport3
    Set .DataSource = rst
    With .Sections("Section1").Controls
    
    
    
    .Item("Name").Caption = "Patient Name: " & rst.Fields("Name").Value
    .Item("RegNo").Caption = "Reg No.: " & rst.Fields("Reg No").Value
    .Item("Age").Caption = "Age/Sex: " & rst.Fields("Age").Value & "/" & rst.Fields("Sex").Value
    .Item("DOA").Caption = "Date of admission: " & Format(rst.Fields("Admitdate").Value, "dd/mm/yyyy")
    .Item("IPDNo").Caption = "IPD No.: " & rst.Fields("Ip No").Value
    .Item("DOD").Caption = "Date of discharge: " & Format(rst.Fields("Dischargedate").Value, "dd/mm/yyyy")
    .Item("Diagnosis").Caption = rst.Fields("Diagnosis").Value
    .Item("History").Caption = rst.Fields("History").Value
    .Item("Examination").Caption = rst.Fields("Examination").Value
    .Item("Hospital").Caption = rst.Fields("Hospital course").Value
    .Item("Investigation").Caption = rst.Fields("Investigations").Value//I wish to print table with grid here
    
    .Item("Treatment").Caption = rst.Fields("Treatment").Value
    .Item("Advise").Caption = rst.Fields("Advise").Value
    .Item("Condition").Caption = rst.Fields("Condition").Value
    If rst.Fields("Operation").Value <> "" Then
    
    .Item("Operation").Caption = rst.Fields("Operation").Value
    .Item("Line9").Visible = True
    .Item("Label10").Visible = True
    .Item("Label22").Visible = True
    Else
    .Item("Operation").Caption = ""
    .Item("Line9").Visible = False
    .Item("Label10").Visible = False
    .Item("Label22").Visible = False
    End If
    
    
    
    
    End With
    
    .Show
    .WindowState = 0
    End With
    
    
    
    
    
    
    
    
    
    Exit Sub
    ErrorHandler:
    
    MsgBox "Oops, an error has occured." & vbCrLf & vbCrLf & "Error Code : " & Err.Number & " , " & Err.Description, vbCritical, "Error"
    Exit Sub
    
    
    End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    49

    Re: Add table with grid in datareport

    should I post it as a new thread as there is no reply?

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    49

    Re: Add table with grid in datareport

    Can anyone help me?

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: Add table with grid in datareport

    Check this older thread, maybe it can be of any help to you:
    https://www.vbforums.com/showthread....091&viewfull=1

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Add table with grid in datareport

    You may want to look up sub reports. Sounds like that may be what you need here. I don't use the data report tool so have no idea how you would need to go about it using that tool though am pretty sure it can be done.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    49

    Re: Add table with grid in datareport

    Quote Originally Posted by Arnoutdv View Post
    Check this older thread, maybe it can be of any help to you:
    https://www.vbforums.com/showthread....091&viewfull=1
    well this post is about datagrid and I dont have datagrid control. I tried to get datafrid but I failed. Please give some other option for this problem

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: Add table with grid in datareport

    Sorry, but I never used the DataReport nor the DataGrid control

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Add table with grid in datareport

    I really can't tell what you are trying to do, but it might be something like:

    Name:  sshot.png
Views: 144
Size:  5.4 KB

    And of course it is possible to add gridlines and such to your DataReport if that's what you insist on.


    In order to do that you need a Relation Query. Those are created using the Data Shaping Service for OLEDB and most plinkers here have probably never even heard of that. They probably have no idea what an ADO Field of type adChapter even is.

    You can craft a Relation Query by hand, but it is much easier to let a DataEnvironment Designer create one for you. After all, that's one of its built in power tools.

    But even if you work out the the query syntax by hand you have the problem of working with a disconnected DataReport Designer while trying to lay out your DataReport.

    Don't bother, just use a DataEnvironment as you are meant to!

    And no, you cannot use a creaky old ADODC for this. It was never designed to handle hierarchical ADO Recordsets.


    If you do this right your program will contain almost no lines of procedural code.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Add table with grid in datareport

    Adding borders to "paint gridlines" of a sort:

    Name:  sshot grid.png
Views: 156
Size:  6.9 KB

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Add table with grid in datareport

    Here is the sample Project.

    Almost 100% of the code here is just to create and populate a Demo database.
    Attached Files Attached Files

  13. #13
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: Add table with grid in datareport

    Quote Originally Posted by dilettante View Post
    Here is the sample Project.

    Almost 100% of the code here is just to create and populate a Demo database.
    Never play with DataReport.
    I have to download and install "Microsoft Access Database Engine 2010 Redistributable" so that I can create the Demo.accdb. But I got "Report width is larger than the Paper width" error.

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Add table with grid in datareport

    You can just substitute the Jet 4.0 OLEDB Provider, it works just as well.

    No idea what paper width you have set for your default printer. You'll have to select another printer and/or change the paper width setting or tweak the DataReport layout for a different paper size.

    Some people use metric sizes like A4 most of the time and that's about 1/4" too narrow for the program as uploaded. You can probably just shave a bit off the left and right margin settings.

    If your programs need to work where users leave the printer settings hosed you might want to add dialogs to the programs for choosing which printer to use, its paper settings, margins, orientation, etc.

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