Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreport not being displayed

Status
Not open for further replies.

substrate

Programmer
Jul 13, 2004
2
CA
OK .. I've been struggling with getting a subreport to display properly within the main report.

I have the Crystal Reports OCX Control on my visual basic form, and I can get the main report to come up and display all the correct data. The data is being read from a MS Access database which has multiple tables inside. The main section of the report reads from the first (main) table inside the Access DB, but there is a subreport that needs to read from a seperate table within that same database.

The "main" table is called tbl_recipe and holds recipe data for a steel milling plant. There is another table called tbl_RollDesign which is where the sub-report needs to get it's data. There are ID's in tbl_recipe which relate to ID's in the tbl_RollDesign table. So the first thing my VB program has to do is find an ID in "tbl_recipe" where the 'Name' and 'Master' fields meet the user input. Then, my program simply needs to pass that ID to the crystal reports control so that it can load up the report with the data for that ID number. Problem is, some times the ID in the 2nd table isn't there -- it needs to grab a different ID from the first table. I'll explain why this happens. In the main table, there is a Name field and a Master (boolean) field. The RollDesign table only holds information for Master recipies. If the user wants to do a report for a non-Master, then it STILL NEEDS TO pull the information from the sub-table using the Master=True condition (because there is never non-master info in the RollDesign table).


So far my code looks like this:
---------------------------------------

dim RS as adodb.recordset
dim autoID as integer
dim query as string

'open the d-base connection to the access database
OpenDataBaseConnection

'set discard saved data
CrystalReport.DiscardSavedData = True

'get the ID from the table where "Name" and "Master"
'(boolean) meet the user conditions. cmb_RecipeName
'is simply a combo box, and opt_Master is an radio button

RS.Open "SELECT ID FROM tbl_recipe WHERE Name='" & cmb_RecipeName.Text & "' AND Master=" & IIf(opt_Master, True, False), CN1, adOpenStatic, adLockReadOnly

'Get the ID from the recordset
autoID = RS_TMP.Fields(0).Value
'Close the recordset
RS.Close
'Set the file name for the report
CrystalReport.ReportFileName = "myReport.rpt"
'Set the query string variable (notice "tbl_recipe")
query = "{tbl_recipe.ID}=" & autoID
'Pass that query string to the control
CrystalReport.SelectionFormula = query

'== everything above works 100% ==

'Now, get the zero'th sub-report name and
'set the control to "look" at that subreport

CrystalReport.SubreportToChange = CrystalReport.GetNthSubreportName(0)

'Now try to pull out the ID where Master=True
'which will be the ID inside tbl_RollDesign

RS.Open "SELECT ID FROM tbl_recipe WHERE Name='" & cmb_RecipeName.Text & "' AND Master=" & True, CN1, adOpenStatic, adLockReadOnly


'And remember that the code BELOW references the
'subreport because i have the .SubreportToChange
'set to the zero'th sub-report in the report

'set the autoID integer variable

autoID = RS.Fields(0).Value
'Close the recordset
RS.Close
'Set the query string variable (notice "tbl_RollDesign")
query = "{tbl_RollDesign.ID}=" & autoID
'make the report use the above query
CrystalReport.SelectionFormula = query
'Stop using the sub-report
CrystalReport.SubreportToChange = ""

=============================

So ... like I said ... main report loads up perfect, it's just that the sub-report just sits there blank. I havn't done any subreport linking inside crystal reports because I don't think I need to ... I should just be able to send it the two queries as above.

Thanks for the help,
-Brian
 
Ok .. nevermind .. I got it working.

Apparantly my "window" for the subreport was too big for the "box" that held the subreport so it just decided to not display it at all.

Shesh ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top