11 Replies - 17255 Views - Last Post: 27 September 2012 - 01:44 AM Rate Topic: -----

#1 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

generate crystal report based on the combobox selection

Posted 19 September 2012 - 11:30 PM

Hi!!
i have a project that i am developing using VB.net.
and now my problem is i got a userform which contains a combobox that get its data from the database (the combobox contains items like 3A,3B,3C,12A etc..) now i placed a button on the userform (Create report Button) which generate a subform where i have 3 check boxes giving the users an option to tick between chosing if he want to generate a report only with all the A items or B items or C items and press OK then the report should be generate based on that selection....but when am pressing OK nothing happen can anyone help me with this????please

Here's my code
[ Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Dim a As Integer
        If ChkLikelihoodA.Checked = False AndAlso ChkLikelihoodB.Checked = False AndAlso ChkLikelihoodC.Checked = False Then
            MsgBox("You must at least choose one type of report you would like to create", vbCritical, "Error")
        Else
            Select Case 1
                Case a
                    If ChkLikelihoodA.Checked = True AndAlso ChkLikelihoodB.Checked = False AndAlso ChkLikelihoodC.Checked = False Then
                        Dim con As New SqlClient.SqlConnection(My.Settings.NewEvapcoDBConnectionString.ToString)
                        Dim cmd As New SqlClient.SqlCommand("Select Tender.ETNumber,Tender.ProjectLocation,Tender.ProjectName,Tender.UnitType From Likelihood INNER JOIN Tender ON Likehood.LikelihoodID = Tender.LikelihoodID WHERE Likelihood.Likelihoodlevel LIKE '%A'")
                        Dim da As New SqlClient.SqlDataAdapter(cmd)
                        Dim ds As New TenderDataSet
                        Dim strReportName As String
                        Dim rptdoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Dim strReportpath As String = ("D:\New EvapcoDB\New EvapcoDB\TenderReport.rpt")

                        Try
                            con.Open()
                            cmd.Connection = con
                            ds.Clear()

                            da.Fill(ds, "TenderReport")
                            strReportName = "TenderReport"

                            If Not IO.File.Exists(strReportpath) Then
                                MsgBox("An Error occured, impossible to find the report", vbCritical, "Error")
                                con.Close()
                                Exit Sub
                            End If

                            rptdoc.Load(strReportpath)
                            rptdoc.SetDataSource(ds.Tables(1))
                            rptdoc.Refresh()
                            ReportTenderForm.TenderCrystalReportViewer.ReportSource = rptdoc
                            ReportTenderForm.TenderCrystalReportViewer.Refresh()
                        Catch ex As Exception
                            System.Windows.Forms.MessageBox.Show(ex.Message)
                        End Try
                    End If
            End Select
        End If
    End Sub]
[/code]

This post has been edited by modi123_1: 19 September 2012 - 11:36 PM
Reason for edit:: please use code tags..


Is This A Good Question/Topic? 0
  • +

Replies To: generate crystal report based on the combobox selection

#2 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 04:53 AM

Anyone willing to help me with my problem pleasee!!!!! i realy need to solve this
Was This Post Helpful? 0
  • +
  • -

#3 jgferguson   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 31
  • Joined: 11-July 12

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 06:05 AM

Hi,

You're first step should be to step through the code line by line to try and work out what the problem is: is your sql string corerct? Is your table populated with data? is the data source of the report set correctly? Also, where is teh report viewed? do you use the ReportViewer control on a new form? and if so where is the code to show the report viewer?

If you are still stuck after doing this then please re-post but with as much information as you can to help us help you.

Hope this helps,
Jerry.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 06:05 AM

It would appear that you're going to have to build your criteria for the WHERE clause off of your checkboxes that are checked and append it to your base SQL statement.
Was This Post Helpful? 0
  • +
  • -

#5 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 07:00 AM

thanks for your replies

Charlie if im not getting u wrong what u mean is my problem is on my sqlcommand?but please i am new to this would you please tell me what part of my code am doing wrong???am kinda stress now i realy can't see what am doing wrong!!!!!!!!!!!!!!!!
Was This Post Helpful? 0
  • +
  • -

#6 jgferguson   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 31
  • Joined: 11-July 12

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 07:47 AM

Hi again,

As a quick pointer since I have had a bit more time to loook at your problem, you have the following:-


Dim a As Integer 

If ChkLikelihoodA.Checked = False AndAlso ChkLikelihoodB.Checked = False AndAlso ChkLikelihoodC.Checked = False Then 

MsgBox("You must at least choose one type of report you would like to create", bCritical, "Error")  

Else 

Select Case 1  

Case a  




Presumably you are assinging an integer value to the variable 'a' then testing what the value is? in whcih case your use of 'Select Case' is the wrong way round - it should be:-

Select Case a

case 1
     'sql code when box 1 is ticked

case 2
     'sql code when box 2 is ticked
etc.

End Select




Not sure if this is main problem but it certainly doesn't look right to me.

Cheers,
Jerry.
Was This Post Helpful? 0
  • +
  • -

#7 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 20 September 2012 - 11:11 PM

Hi Jerry

thanks for your reply but i don't think that my main problem....The problem is am not able to display my report on the report viewer after clicking on OK button and am not getting any error message and from what you suggested yesterday i have checked evrithing and i found out that my table is populated, the data source is set correctly and yes i am using report viewer..

Regards!!

Chris
Was This Post Helpful? 0
  • +
  • -

#8 jgferguson   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 31
  • Joined: 11-July 12

Re: generate crystal report based on the combobox selection

Posted 21 September 2012 - 01:24 AM

Hi Chris,

From what I can see there is no line that actually displays the report. I am assuming the object 'ReportTenderForm' is the form that contains the ReportViewer control to display the Crystal report on the screen but there is no call to show this form as in

ReportTenderForm.Show()



I see you are loading the report from file - in my projects the report is an object within the project solution (in the same way as a form or class etc).

It would help if you could tell me what you do see - do you get the TenderReport form loaded with the report template but no data or do you get the report form displayed on the screen but no report template at all or do you not get the form with the report viewer displayed at all?

I use the following code layout for displaying Crystal Reports on screen to the user:

Dim RepViewer As New RepViewer   'name of the form that contains the Crystal ReportViewer control
RepViewer.MdiParent = MDIParent1

Dim Summary As New Summary       'name of the report within the VB solution

'code here to set database connnection and sql string


Dim DA As New MySql.Data.MySqlClient.MySqlDataAdapter(sql, cn)

Dim DT As New DataTable

DA.Fill(DT)

Summary.SetDataSource(DT)    'sets the data source of the report to the datatable

RepViewer.CrystalReportViewer1.ReportSource = Summuary     
'sets the source of the report viewer control to the populated report

RepViewer.Show()     'displays the report viewer form on the screen




Hope this helps.
Jerry.
Was This Post Helpful? 0
  • +
  • -

#9 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 21 September 2012 - 01:58 AM

Thanks again Jerry for your good intention to help

let me explain again my scenario to you.

1) i have the main form called Tender form, a form where the users enter all infos about the tender and save evrithng into my DB and this work very fine for me.
then on that form i have a button called Create Report,when the user click on that button its displays a msgbox asking the user YES or NO he wants to create the report..If the user click NO nothing happen ..but if the user click YES then the REPORT TENDER FORM (Which contains a button called SHOW REPORT) appears

NOW HERE'S MY PROBLEM:

after the report tender form appears the user must click on the show report button then now a small form with checkboxes appears that now where the user chooses if he want the report onli with LikeliHood containing the character A or B or C or both then after tickng the checkbox he must press OK then the report must be display on the REPORT TENDER FORM but i am getting nothing after i click the OK button.....i realy don't understand WHY??

am realy sorry if my problem is so stupid but i know learning is the key to success!!!!!!!!
Was This Post Helpful? 0
  • +
  • -

#10 jgferguson   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 31
  • Joined: 11-July 12

Re: generate crystal report based on the combobox selection

Posted 21 September 2012 - 02:45 AM

Hi Chris,

All is a little bit clearer now. The problem is that you have a ReportForm which is opened and then subsequently open the CheckBoxForm and return to the ReportForm. I presume that the code on the TenderForm will have something along the lines of:-

Dim ReportForm as New ReportForm
ReportForm.Show()




or something similar. In order to make the methods on the ReportForm perform as you expect you will need to declare it at a Public level. To do this you need to add a module to your project and within that module declare the form using the Public keyword.

Module Module1

     Public ReportForm as New ReportForm

End Module



Then in the TenderForm change the code that opens the ReportForm to be something along the lines of:-

ReportForm = New ReportFOrm
'note there is no Dim statement at the start of this line. 



This will allow the methods and objects that are created within the Reportform to be accessed from another form (the CheckBoxForm) and allow dynamic updates to the content of the ReportForm.

It took me ages to work this out when I needed to but this method works for me.

Hope this solves your problem.
Jerry.
Was This Post Helpful? 0
  • +
  • -

#11 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 26 September 2012 - 11:08 PM

Hi Jerry!!

sorry for not hearing from me i was doing some other projects....i tried to do what you suggest in your previous post but now when am cliking on the button that shows the report i am only getting the message from my msgbox (CHECK MY CODE ON MY FIRST POST) where its says "You must at least choose one type of report you want to create" even if i select the type of report i want....

regards!!
Chris
Was This Post Helpful? 0
  • +
  • -

#12 christian Mukeba   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 96
  • Joined: 06-September 12

Re: generate crystal report based on the combobox selection

Posted 27 September 2012 - 01:44 AM

Thanks alot Jerry i found how to resolve my issues but now i have another problem which is when am showing the repot only the items from the tender are showing the one from other tables are not showing....is ther any possibility that you may know what the problem is??

i have a sqlquery like:
 Dim cmd As New SqlClient.SqlCommand("Select Tender.ETNumber, Tender.EnquiryDate,Tender.ProjectName, Tender.UnitType, Tender.ReqDate, Tender.NumberUnits, Sales.SalesPerson From Likelihood INNER JOIN Tender ON Likelihood.LikelihoodID = Tender.LikelihoodID INNER JOIN Sales ON Tender.SalesID = Sales.SalesID WHERE Likelihood.Likelihoodlevel LIKE '%A'")

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1