SantosElGoode
Programmer
myrep.Database.Tables.Delete 1
Why will this code not work? It doesn't just not work it crashs VB everytime I call it.If there another property I must set to allow me delete a table.
----------------------------------------------------------
Here is the whole code to the function, which is called in the unloading of the form.
Public Sub delete_details()
Dim total_controls As Integer
Dim myitem As CRAXDRT.IReportObject
Dim Mysection As CRAXDRT.Section
Set Mysection = myrep.Sections(2)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = myrep.Sections(3)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = Nothing
Set myitem = Nothing
myrep.Database.Tables.Delete 1
End Sub
----------------------------------------------------
The table I wish to delete is a disconnected recordset, and I have set as table 1, with function here in the load function
myrep.Database.Tables.Add " ", , rs, , "p2smon.dll"
I could ignore the delete function only for the fact, even after I destory myrep, this table remains in the report,So when It is being loaded again it loads the old data.
I have also tried using the function "DiscardSavedData", this produces the same problem as "tables.delete"
Any ideas would be great !!
here is the complete source code
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
Public rs As ADODB.Recordset
Public report_title As String
Dim myrep As CRAXDRT.Report
Private Sub Form_Load()
Dim mytitle As CRAXDRT.TextObject
Set myrep = Report_templete
myrep.Database.Tables.Add " ", , rs, , "p2smon.dll"
myrep.DiscardSavedData
add_details
CRViewer1.ReportSource = myrep
CRViewer1.ViewReport
End Sub
------------------------------------------------------
Public Sub add_details()
Dim Mysection As CRAXDRT.Section
Dim myfield As CRAXDRT.FieldObject
Dim mytext As CRAXDRT.TextObject
Dim section_top As Double
Dim section_width As Double
Dim last_max As Double
Dim field_name As String
For i = 0 To rs.Fields.Count - 1
For i = 0 To myrep.Database.Tables(myrep.Database.Tables.Count).Fields.Count - 1
'"{ado." & rs.Fields(i).Name & "}"
field_name = myrep.Database.Tables(myrep.Database.Tables.Count).Fields(i).Name
Set Mysection = myrep.Sections.Item(3)
'Set myfield = Mysection.AddUnboundFieldObject(crStringField, last_max, 0)
'myfield.SetUnboundFieldSource "{ado." & rs.Fields(i).Name & "}"
Set myfield = Mysection.AddFieldObject("{ado." & field_name & "}", last_max, 0)
myfield.CanGrow = True
myfield.LeftIndent = True
myfield.Suppress = False
myfield.HorAlignment = crLeftAlign
Set Mysection = myrep.Sections.Item(2)
Set mytext = Mysection.AddTextObject(rs.Fields(i).Name, last_max, 10)
mytext.CanGrow = True
mytext.Width = myfield.Width
mytext.HorAlignment = crLeftAlign
mytext.Font.Bold = True
last_max = myfield.Left + myfield.Width
Next
End Sub
-----------------------------------------------------------
Public Sub delete_details()
Dim total_controls As Integer
Dim myitem As CRAXDRT.IReportObject
Dim Mysection As CRAXDRT.Section
Set Mysection = myrep.Sections(2)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = myrep.Sections(3)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = Nothing
Set myitem = Nothing
'myrep.Database.Tables.Delete 1
End Sub
-----------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
delete_details
Set myrep = Nothing
End Sub
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
Why will this code not work? It doesn't just not work it crashs VB everytime I call it.If there another property I must set to allow me delete a table.
----------------------------------------------------------
Here is the whole code to the function, which is called in the unloading of the form.
Public Sub delete_details()
Dim total_controls As Integer
Dim myitem As CRAXDRT.IReportObject
Dim Mysection As CRAXDRT.Section
Set Mysection = myrep.Sections(2)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = myrep.Sections(3)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = Nothing
Set myitem = Nothing
myrep.Database.Tables.Delete 1
End Sub
----------------------------------------------------
The table I wish to delete is a disconnected recordset, and I have set as table 1, with function here in the load function
myrep.Database.Tables.Add " ", , rs, , "p2smon.dll"
I could ignore the delete function only for the fact, even after I destory myrep, this table remains in the report,So when It is being loaded again it loads the old data.
I have also tried using the function "DiscardSavedData", this produces the same problem as "tables.delete"
Any ideas would be great !!
here is the complete source code
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
Public rs As ADODB.Recordset
Public report_title As String
Dim myrep As CRAXDRT.Report
Private Sub Form_Load()
Dim mytitle As CRAXDRT.TextObject
Set myrep = Report_templete
myrep.Database.Tables.Add " ", , rs, , "p2smon.dll"
myrep.DiscardSavedData
add_details
CRViewer1.ReportSource = myrep
CRViewer1.ViewReport
End Sub
------------------------------------------------------
Public Sub add_details()
Dim Mysection As CRAXDRT.Section
Dim myfield As CRAXDRT.FieldObject
Dim mytext As CRAXDRT.TextObject
Dim section_top As Double
Dim section_width As Double
Dim last_max As Double
Dim field_name As String
For i = 0 To rs.Fields.Count - 1
For i = 0 To myrep.Database.Tables(myrep.Database.Tables.Count).Fields.Count - 1
'"{ado." & rs.Fields(i).Name & "}"
field_name = myrep.Database.Tables(myrep.Database.Tables.Count).Fields(i).Name
Set Mysection = myrep.Sections.Item(3)
'Set myfield = Mysection.AddUnboundFieldObject(crStringField, last_max, 0)
'myfield.SetUnboundFieldSource "{ado." & rs.Fields(i).Name & "}"
Set myfield = Mysection.AddFieldObject("{ado." & field_name & "}", last_max, 0)
myfield.CanGrow = True
myfield.LeftIndent = True
myfield.Suppress = False
myfield.HorAlignment = crLeftAlign
Set Mysection = myrep.Sections.Item(2)
Set mytext = Mysection.AddTextObject(rs.Fields(i).Name, last_max, 10)
mytext.CanGrow = True
mytext.Width = myfield.Width
mytext.HorAlignment = crLeftAlign
mytext.Font.Bold = True
last_max = myfield.Left + myfield.Width
Next
End Sub
-----------------------------------------------------------
Public Sub delete_details()
Dim total_controls As Integer
Dim myitem As CRAXDRT.IReportObject
Dim Mysection As CRAXDRT.Section
Set Mysection = myrep.Sections(2)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = myrep.Sections(3)
total_controls = Mysection.ReportObjects.Count
For i = 0 To total_controls - 1
Set myitem = Mysection.ReportObjects(Mysection.ReportObjects.Count)
Mysection.DeleteObject myitem
Next
Set Mysection = Nothing
Set myitem = Nothing
'myrep.Database.Tables.Delete 1
End Sub
-----------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
delete_details
Set myrep = Nothing
End Sub
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------