Results 1 to 10 of 10

Thread: [RESOLVED] Need help with datareport / dataenvironment

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    13

    Resolved [RESOLVED] Need help with datareport / dataenvironment

    Hi everyone,

    I have a form that displays customers, in a combobox. You select one and click a command button.

    it then generates another combobox with the month usage reports. you select a month to view and click a command button.

    This brings up the datareport with the data for that time period.

    This all works.

    if you then select another month and click the command button it will display the same info again.
    I have used debug.print, gotta love it, and it shows that the sql is different. But the report is still the same. this is how i change the command text.

    VB Code:
    1. DataEnvironment1.Commands.Item("Command2").CommandText = strsql
    2.     DataEnvironment1.Commands.Item("Command2").Execute strsql

    why doesn't it work.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help with datareport / dataenvironment

    The datareport data-bound at design time? Try refreshing the data report; datareport1.refresh

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    13

    Re: Need help with datareport / dataenvironment

    I have tried that, no luck. When I load the form and choose a month it works properly, its just when you try and select another month that is doesn't refresh.
    VB Code:
    1. Dim strsql As String
    2.     strsql = "SELECT DISTINCT * FROM rpt_tsheet WHERE t_empnum= '" & frmTSheetSelect.cmbDomestic.Tag & "' AND t_id =" & frmTSheetSelect.cmbDomestic1.Tag & ""
    3.     Debug.Print "CHECK " & strsql
    4.    
    5.     DataEnvironment1.Commands.Item("Command2").CommandText = strsql
    6.     DataEnvironment1.Commands.Item("Command2").Execute strsql
    7.        
    8.     rptDomestic.Refresh

    That is all my code on the report. Yes it is data bound.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help with datareport / dataenvironment

    Try resetting the datasource property of the report.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    13

    Re: Need help with datareport / dataenvironment

    when i try this
    VB Code:
    1. rptDomestic.DataSource = DataEnvironment1

    it tells me 'Method or data member not found'

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help with datareport / dataenvironment

    You need to set it to an ADO recordset. Try this

    Set rptDomestic.DataSource = DataEnvironment1.Commands.Item("Command2").Execute(strsql)

    If that doesn;t work then we'll use non-bound methods

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help with datareport / dataenvironment

    Or maybe you could zip it up along with DB (is the db large?)

    Hard to come up with a solution cause we have no code we can refer to... and the databound properties only you can see their values.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    13

    Re: Need help with datareport / dataenvironment

    Thanks for your help so far, unfortunately I can't attach the code or the db - I could get into trouble :-(

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need help with datareport / dataenvironment

    I usually don't use the dataenvironment cause its just a graphical wrapper for ado hence there's additional memory use. You can do something like this at run time.

    VB Code:
    1. Public Sub ShowDomesticReport()
    2. 'Dim conn As New ADODB.Connection  'assume already open
    3. Dim rs As ADODB.Recordset
    4. Dim rpt As New rptDomestic
    5. Dim strSQL as String
    6.  
    7.    strSQL = "SELECT DISTINCT * FROM rpt_tsheet WHERE t_empnum= '" & _
    8.       frmTSheetSelect.cmbDomestic.Tag & "' AND t_id =" & _
    9.       frmTSheetSelect.cmbDomestic1.Tag & ""
    10.  
    11. On Error Goto Err_Handler
    12.    Set rs = conn.Execute strsql
    13.  
    14.    'Header section labels and report caption
    15.    With rpt.Section("Header")
    16.       .Controls("lblCompany").Caption = Form1.lblCompany.Caption
    17.       .Controls("lblAdd1").Caption = Form1.txtAddress1.Text
    18.       .Controls("lblAdd2").Caption = Form1.txtAddress2.Text
    19.    End With
    20.    rpt.Caption = "Domestic Report"
    21.  
    22.    'Set datasource and bind recordset fields.
    23.    'Update fields and datareport control names to those you use
    24.    Set rpt.DataSource = rs
    25.    With rpt.Section("Details")
    26.         .Controls("txtQuantity").DataField = "Quantity"    'where quantity is a field in the recordset
    27.         .Controls("txtUnit").DataField = "Unit"
    28.         .Controls("txtParticulars").DataField = "Particulars"
    29.         .Controls("txtUnitPrice").DataField = "Unit Price"
    30.         .Controls("txtAmount").DataField = "Amount"
    31.    End With
    32.    
    33.    rpt.Show vbModal
    34.    rs.Close
    35.    Unload rpt
    36.    Set rs = Nothing
    37.    Set rpt = Nothing
    38.    
    39.    Exit Sub
    40.  
    41. Err_Handler:
    42.    'your error handling code
    43. End Sub
    Last edited by leinad31; Oct 19th, 2006 at 04:40 AM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    13

    Re: Need help with datareport / dataenvironment

    leinad31, dude, you're the king!

    Thanks that did the trick.

    I rate you thus.

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