Pass user input from form To Report Viewer using SQL SELECT ... @var

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
/*
SQL 2008
Visual Studio 2013 - Report Viewer

My vb skill level: Poor but I'm excited to learn

Profession: DBA
- Can I set up the sql connection in VB? - YES
- Can I set up the NAME, Data Source, and Table Adapter in VB? - YES

ERROR:
Argument Not Specified For Parameter
*/

Please guys, I know how uncool it is to ask for a extra "hand holding", but I'm really new at this and realize I'm over my head so I would be very greatfull for your extra patience. Very Sincerely....

1. Here is my Form
my-form.jpg

2. Here is my SELECT statement
SELECT * FROM dbo.procurement_goods WHERE MONTH(date) = @month AND YEAR(date) = @year

3.
This is My Table Adapter
Screenshot - 12_27_2015 , 9_25_31 PM.jpg
parameters.jpg

4. My Code in Visual Studio
I'm posting my new code here and my question to you is: what should my code look like to resolve the missing parameter?

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms

Public Class REPORT_monthly_Procurement_goods
    Dim conn As SqlConnection
    Dim comm As SqlCommand

    Private Sub openconnection()
        conn = New SqlConnection
        conn.ConnectionString = "server=myserver;database=mydb;Integrated Security=SSPI;"
        conn.Open()
    End Sub

    Private Sub ComboBox_MONTH_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_MONTH.SelectedIndexChanged
        'Convert Month Name to INT
        Dim var_month As String
        If ComboBox_MONTH.SelectedItem.ToString = "January" Then var_month = "1"
        If ComboBox_MONTH.SelectedItem.ToString = "February" Then var_month = "2"
        If ComboBox_MONTH.SelectedItem.ToString = "March" Then var_month = "3"
        If ComboBox_MONTH.SelectedItem.ToString = "April" Then var_month = "4"
        If ComboBox_MONTH.SelectedItem.ToString = "May" Then var_month = "5"
        If ComboBox_MONTH.SelectedItem.ToString = "June" Then var_month = "6"
        If ComboBox_MONTH.SelectedItem.ToString = "July" Then var_month = "7"
        If ComboBox_MONTH.SelectedItem.ToString = "August" Then var_month = "8"
        If ComboBox_MONTH.SelectedItem.ToString = "September" Then var_month = "9"
        If ComboBox_MONTH.SelectedItem.ToString = "October" Then var_month = "10"
        If ComboBox_MONTH.SelectedItem.ToString = "November" Then var_month = "11"
        If ComboBox_MONTH.SelectedItem.ToString = "December" Then var_month = "12"
    End Sub

    Private Sub ComboBox_YEAR_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_YEAR.SelectedIndexChanged

    End Sub

    Private Sub go_button_Click(sender As Object, e As EventArgs) Handles go_button.Click
        comm.Parameters.AddWithValue("@month", CInt(ComboBox_MONTH.Text))
        comm.Parameters.AddWithValue("@year", CInt(ComboBox_YEAR.Text))
    End Sub

    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Errors here:
        Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods)

        Me.ReportViewer1.RefreshReport()
    End Sub

End Class

Argument-error1.jpg
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
Where it's erroring, it looks like you're calling just the Fill() method without passing in the Month & Year values.

IE instead of:
Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods)
Should be:
Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
You'll need to move the var_month variable out of the ComboBox_MONTH_SelectedIndexChanged event sub and make it a Decimal type. You'll also need to get the year value from the ComboBox and pass it in as a Decimal.
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Where it's erroring, it looks like you're calling just the Fill() method without passing in the Month & Year values.

IE instead of:
Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods)
Should be:
Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
You'll need to move the var_month variable out of the ComboBox_MONTH_SelectedIndexChanged event sub and make it a Decimal type. You'll also need to get the year value from the ComboBox and pass it in as a Decimal.
Your suggestion has helped !!

here is my new line: Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, ComboBox_MONTH, ComboBox_YEAR)

The original error has gone away and now I'm getting an error for 'ComboBox_YEAR' and 'ComboBox_Month' that says the following: VALUE OF TYPE CANNOT BE CONVERTED TO DECIMAL



 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
Your suggestion has helped !!

here is my new line: Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, ComboBox_MONTH, ComboBox_YEAR)

The original error has gone away and now I'm getting an error for 'ComboBox_YEAR' and 'ComboBox_Month' that says the following: VALUE OF TYPE CANNOT BE CONVERTED TO DECIMAL



From the sounds of it you're getting that error message because you're passing in the ComboBox's themselves rather than a value.
Like I mentioned you're going to want to pass in the month number (as a Decimal) from what they selected.

Probably something like:
    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim MonthValue, YearValue As Decimal
        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1D
            Case "February" : MonthValue = 2D
            Case "March" : MonthValue = 3D
            Case "April" : MonthValue = 4D
            Case "May" : MonthValue = 5D
            Case "June" : MonthValue = 6D
            Case "July" : MonthValue = 7D
            Case "August" : MonthValue = 8D
            Case "September" : MonthValue = 9D
            Case "October" : MonthValue = 10D
            Case "November" : MonthValue = 11D
            Case "December" : MonthValue = 12D
            Case Else : MonthValue = 0D
        End Select

        If Not Decimal.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = CDec(DateTime.Today.Year)

        Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
 
        Me.ReportViewer1.RefreshReport()
    End Sub

But you'll have to try it and make sure this works.
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
From the sounds of it you're getting that error message because you're passing in the ComboBox's themselves rather than a value.
Like I mentioned you're going to want to pass in the month number (as a Decimal) from what they selected.

Probably something like:
    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim MonthValue, YearValue As Decimal
        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1D
            Case "February" : MonthValue = 2D
            Case "March" : MonthValue = 3D
            Case "April" : MonthValue = 4D
            Case "May" : MonthValue = 5D
            Case "June" : MonthValue = 6D
            Case "July" : MonthValue = 7D
            Case "August" : MonthValue = 8D
            Case "September" : MonthValue = 9D
            Case "October" : MonthValue = 10D
            Case "November" : MonthValue = 11D
            Case "December" : MonthValue = 12D
            Case Else : MonthValue = 0D
        End Select

        If Not Decimal.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = CDec(DateTime.Today.Year)

        Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
 
        Me.ReportViewer1.RefreshReport()
    End Sub

But you'll have to try it and make sure this works.
I tried it and failed.
But the failure was not due to your example.

Upon clicking a button on a previous form that launches the report viewer form. I get the following error. 1_9_2016 , 12_05_17 PM.jpg

However, I believe the above error is because I'm calling the report viewer form before I have a chance to enter the month and year values that the viewer needs.
In other words I have both the report viewer AND the combo boxes on the same form like this.
View attachment 4272


To resolve this should I:
(A) Remove the combo boxes and 'GO' button from the report viewer form so that the report viewer form only has the report viewer.
(B) Build a simple form called 'MMYY' containing the month and year combo boxes and a GO button that would call the report viewer form AND pass the combo box values values from the MMYY form to the Report Viewer?

If so how do I pass the values from MMYY form to the report viewer so that they can be used as the input values that the report viewer needs????

Or could I be going about this all wrong? :) :)
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
I tried it and failed.
But the failure was not due to your example.

Upon clicking a button on a previous form that launches the report viewer form. I get the following error.

However, I believe the above error is because I'm calling the report viewer form before I have a chance to enter the month and year values that the viewer needs.
In other words I have both the report viewer AND the combo boxes on the same form like this.


To resolve this should I:
(A) Remove the combo boxes and 'GO' button from the report viewer form so that the report viewer form only has the report viewer.
(B) Build a simple form called 'MMYY' containing the month and year combo boxes and a GO button that would call the report viewer form AND pass the combo box values values from the MMYY form to the Report Viewer?

If so how do I pass the values from MMYY form to the report viewer so that they can be used as the input values that the report viewer needs????

Or could I be going about this all wrong? :) :)
Actually I would either:
  • Remove the "Me.procurement_goodsTableAdapter.Fill(...)" and "Me.ReportViewer1.RefreshReport()" lines from the Load event.
  • Have the form automatically set the current Month & Year values in both ComboBox's, then since those values are known at that point use them in the "Me.procurement_goodsTableAdapter.Fill(...)" part.
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Actually I would either:
  • Remove the "Me.procurement_goodsTableAdapter.Fill(...)" and "Me.ReportViewer1.RefreshReport()" lines from the Load event.
  • Have the form automatically set the current Month & Year values in both ComboBox's, then since those values are known at that point use them in the "Me.procurement_goodsTableAdapter.Fill(...)" part.
Will do!
I'll report back to you asap!!!!
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Actually I would either:
  • Remove the "Me.procurement_goodsTableAdapter.Fill(...)" and "Me.ReportViewer1.RefreshReport()" lines from the Load event.
  • Have the form automatically set the current Month & Year values in both ComboBox's, then since those values are known at that point use them in the "Me.procurement_goodsTableAdapter.Fill(...)" part.

  • "Remove the "Me.procurement_goodsTableAdapter.Fill(...)" and "Me.ReportViewer1.RefreshReport()" lines from the Load event." DONE
  • "Have the form automatically set the current Month & Year values in both ComboBox's", DONE

"then since those values are known at that point use them in the Me.procurement_goodsTableAdapter.Fill(...) part?" <-- Juggalo, can you give me an example please?
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
  • "Remove the "Me.procurement_goodsTableAdapter.Fill(...)" and "Me.ReportViewer1.RefreshReport()" lines from the Load event." DONE
  • "Have the form automatically set the current Month & Year values in both ComboBox's", DONE

"then since those values are known at that point use them in the Me.procurement_goodsTableAdapter.Fill(...) part?" <-- Juggalo, can you give me an example please?
Sure can, to start the year is super simple to get just use DateTime.Now.Year and you can also get the current month as an integer with DateTime.Now.Month. Just use those values to set the SelectedItem or SelectedIndex of each of the ComboBoxes respectively, also pass those into the .Fill() method if you still have that method call in your Form_Load event.
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Sure can, to start the year is super simple to get just use DateTime.Now.Year and you can also get the current month as an integer with DateTime.Now.Month. Just use those values to set the SelectedItem or SelectedIndex of each of the ComboBoxes respectively, also pass those into the .Fill() method if you still have that method call in your Form_Load event.
Juggalo,
I've also sent you a private message that might interest you.

You mentioned: just use DateTime.Now.Year <--- Can you show me where this should go??

Here's my code again. Please take a look at the combo box lines where I tried DateTime.Now.Year :)

-------------------------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms


Public Class REPORT_monthly_Procurement_goods
    Dim conn As SqlConnection
    Dim comm As SqlCommand
    Private Sub openconnection()
        conn = New SqlConnection
        conn.ConnectionString = "server=hopue;database=cacao;Integrated Security=SSPI;"
        '''''''''''comm.CommandText = "procurement_goods"
        '''''''''''comm.CommandType = CommandType.TableDirect
        conn.Open()
    End Sub
   


    Private Sub ComboBox_MONTH_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_MONTH = DateAndTime.Now.Month[/B]
    End Sub

    Private Sub ComboBox_YEAR_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_YEAR = DateAndTime.Now.Year[/B]
    End Sub


    Private Sub go_button_Click(sender As Object, e As EventArgs)
        comm.Parameters.AddWithValue("@month", CInt(ComboBox_MONTH.Text))
        comm.Parameters.AddWithValue("@year", CInt(ComboBox_YEAR.Text))
    End Sub


    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MonthValue, YearValue As Decimal


        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1D
            Case "February" : MonthValue = 2D
            Case "March" : MonthValue = 3D
            Case "April" : MonthValue = 4D
            Case "May" : MonthValue = 5D
            Case "June" : MonthValue = 6D
            Case "July" : MonthValue = 7D
            Case "August" : MonthValue = 8D
            Case "September" : MonthValue = 9D
            Case "October" : MonthValue = 10D
            Case "November" : MonthValue = 11D
            Case "December" : MonthValue = 12D
            Case Else : MonthValue = 0D
        End Select


        If Not Decimal.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = CDec(DateTime.Today.Year)


        Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)


        ' Me.ReportViewer1.RefreshReport()
    End Sub




    Private Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load


    End Sub




    Private Sub ComboBox_YEAR_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ComboBox_YEAR.SelectedIndexChanged


    End Sub
End Class
 
Last edited by a moderator:

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
You don't set what's selected in a combobox's SelectedIndexChanged event, that event is what fires when the user selects something in it, so this code:
    Private Sub ComboBox_MONTH_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_MONTH = DateAndTime.Now.Month[/B]
    End Sub
 
    Private Sub ComboBox_YEAR_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_YEAR = DateAndTime.Now.Year[/B]
    End Sub
Isn't needed at all.
What you need to do is in the Load event set each combobox using DateTime.Now, like so:
Dim YearStr As String = DateTime.Now.ToString()

For Count As Integer = 0 To ComboBox_YEAR.Items.Count - 1
    If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
Next

ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
You don't set what's selected in a combobox's SelectedIndexChanged event, that event is what fires when the user selects something in it, so this code:
    Private Sub ComboBox_MONTH_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_MONTH = DateAndTime.Now.Month[/B]
    End Sub
 
    Private Sub ComboBox_YEAR_SelectedIndexChanged(sender As Object, e As EventArgs)
[B][I]       Like this?? ---> [/I]Me.ComboBox_YEAR = DateAndTime.Now.Year[/B]
    End Sub
Isn't needed at all.
What you need to do is in the Load event set each combobox using DateTime.Now, like so:
Dim YearStr As String = DateTime.Now.ToString()

For Count As Integer = 0 To ComboBox_YEAR.Items.Count - 1
    If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
Next

ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1
DONE
I also declared Counter as INT16

Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DSOURCE_ProcurementGoodsTABLE.procurement_goods' table. You can move, or remove it, as needed.

Dim MonthValue, YearValue As Decimal
Dim YearStr As String = DateTime.Now.ToString()
Dim Counter As Int16 <--- Hope this is right


Select Case ComboBox_MONTH.SelectedItem.ToString
Case "January" : MonthValue = 1D
Case "February" : MonthValue = 2D
Case "March" : MonthValue = 3D
Case "April" : MonthValue = 4D
Case "May" : MonthValue = 5D
Case "June" : MonthValue = 6D
Case "July" : MonthValue = 7D
Case "August" : MonthValue = 8D
Case "September" : MonthValue = 9D
Case "October" : MonthValue = 10D
Case "November" : MonthValue = 11D
Case "December" : MonthValue = 12D
Case Else : MonthValue = 0D
End Select


For Count As Integer = 0 To ComboBox_YEAR.Items.Count - 1
If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter

Next
ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1


If Not Decimal.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = CDec(DateTime.Today.Year)
Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)


' Me.ReportViewer1.RefreshReport()
End Sub
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
How about you either post the entire code you have as it is for that form or you zip & attach the project so I can see what all you have going on.
When attaching your project, be sure to delete the bin & obj folders.
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
How about you either post the entire code you have as it is for that form or you zip & attach the project so I can see what all you have going on.
When attaching your project, be sure to delete the bin & obj folders.
Thank you !
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms

Public Class REPORT_monthly_Procurement_goods
    Dim conn As SqlConnection
    Dim comm As SqlCommand

    Private Sub openconnection()
        conn = New SqlConnection
        conn.ConnectionString = "server=####;database=####;Integrated Security=SSPI;"
        '''''''''''comm.CommandText = "procurement_goods"
        '''''''''''comm.CommandType = CommandType.TableDirect
        conn.Open()
    End Sub
   


    Private Sub ComboBox_MONTH_SelectedIndexChanged(sender As Object, e As EventArgs)


    End Sub
    Private Sub ComboBox_YEAR_SelectedIndexChanged(sender As Object, e As EventArgs)


    End Sub
    Private Sub go_button_Click(sender As Object, e As EventArgs)
        comm.Parameters.AddWithValue("@month", CInt(ComboBox_MONTH.Text))
        comm.Parameters.AddWithValue("@year", CInt(ComboBox_YEAR.Text))
    End Sub

    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DSOURCE_ProcurementGoodsTABLE.procurement_goods' table. You can move, or remove it, as needed.
        Dim MonthValue, YearValue As Decimal
        Dim YearStr As String = DateTime.Now.ToString()
        Dim Counter As Int16
        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1D
            Case "February" : MonthValue = 2D
            Case "March" : MonthValue = 3D
            Case "April" : MonthValue = 4D
            Case "May" : MonthValue = 5D
            Case "June" : MonthValue = 6D
            Case "July" : MonthValue = 7D
            Case "August" : MonthValue = 8D
            Case "September" : MonthValue = 9D
            Case "October" : MonthValue = 10D
            Case "November" : MonthValue = 11D
            Case "December" : MonthValue = 12D
            Case Else : MonthValue = 0D
        End Select


        For Count As Integer = 0 To ComboBox_YEAR.Items.Count - 1
            If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
        Next
        ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1


        If Not Decimal.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = CDec(DateTime.Today.Year)


        Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)


        ' Me.ReportViewer1.RefreshReport()
    End Sub


    Private Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load


    End Sub


    Private Sub ComboBox_YEAR_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ComboBox_YEAR.SelectedIndexChanged


    End Sub
End Class
 
Last edited:

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
Of course I don't have your project to actually run this, but I believe this is what you're needing:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
 
Public Class REPORT_monthly_Procurement_goods
 
    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Select the current year in the ComboBox
        ComboBox_YEAR.SelectedIndex = 0I
        For Counter As Integer = 0I To ComboBox_YEAR.Items.Count - 1I
            If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
        Next Counter
		
        'Select the current month in the ComboBox
        ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1

        Call LoadReport(DateTime.Now.Month, DateTime.Now.Year)
    End Sub
    
    Private Sub go_button_Click(sender As Object, e As EventArgs) Handles go_button.Click
        Dim YearValue As Integer
        If Not Integer.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = DateTime.Today.Year
        Call LoadReport(GetMonthInteger(), YearValue)
    End Sub
	
    Private Sub LoadReport(MonthValue As Integer, YearValue As Integer)
        Try
            Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
            Me.ReportViewer1.RefreshReport()
        Catch Ex As Exception
            MessageBox.Show(String.Format("Error getting data for the report:{0}{1}", Environment.NewLine, Ex.ToString()))
        End Try
    End Sub

    Private Function GetMonthInteger() As Integer
        Dim MonthValue As Integer

        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1I
            Case "February" : MonthValue = 2I
            Case "March" : MonthValue = 3I
            Case "April" : MonthValue = 4I
            Case "May" : MonthValue = 5I
            Case "June" : MonthValue = 6I
            Case "July" : MonthValue = 7I
            Case "August" : MonthValue = 8I
            Case "September" : MonthValue = 9I
            Case "October" : MonthValue = 10I
            Case "November" : MonthValue = 11I
            Case "December" : MonthValue = 12I
            Case Else : MonthValue = 0I
        End Select
		
        Return MonthValue
    End Function
	
End Class
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Of course I don't have your project to actually run this, but I believe this is what you're needing:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
 
Public Class REPORT_monthly_Procurement_goods
 
    Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Select the current year in the ComboBox
        ComboBox_YEAR.SelectedIndex = 0I
        For Counter As Integer = 0I To ComboBox_YEAR.Items.Count - 1I
            If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
        Next Counter
        
        'Select the current month in the ComboBox
        ComboBox_YEAR.SelectedIndex = DateTime.Now.Month - 1

        Call LoadReport(DateTime.Now.Month, DateTime.Now.Year)
    End Sub
    
    Private Sub go_button_Click(sender As Object, e As EventArgs) Handles go_button.Click
        Dim YearValue As Integer
        If Not Integer.TryParse(ComboBox_YEAR.SelectedItem.ToString, YearValue) Then YearValue = DateTime.Today.Year
        Call LoadReport(GetMonthInteger(), YearValue)
    End Sub
    
    Private Sub LoadReport(MonthValue As Integer, YearValue As Integer)
        Try
            Me.procurement_goodsTableAdapter.Fill(Me.DSOURCE_ProcurementGoodsTABLE.procurement_goods, MonthValue, YearValue)
            Me.ReportViewer1.RefreshReport()
        Catch Ex As Exception
            MessageBox.Show(String.Format("Error getting data for the report:{0}{1}", Environment.NewLine, Ex.ToString()))
        End Try
    End Sub

    Private Function GetMonthInteger() As Integer
        Dim MonthValue As Integer

        Select Case ComboBox_MONTH.SelectedItem.ToString
            Case "January" : MonthValue = 1I
            Case "February" : MonthValue = 2I
            Case "March" : MonthValue = 3I
            Case "April" : MonthValue = 4I
            Case "May" : MonthValue = 5I
            Case "June" : MonthValue = 6I
            Case "July" : MonthValue = 7I
            Case "August" : MonthValue = 8I
            Case "September" : MonthValue = 9I
            Case "October" : MonthValue = 10I
            Case "November" : MonthValue = 11I
            Case "December" : MonthValue = 12I
            Case Else : MonthValue = 0I
        End Select
        
        Return MonthValue
    End Function
    
End Class

***Running it NOW. Stand by***
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Hi,
I noticed YearStr needs to be declared.

Dim YearStr As String ????
YearStr = 2015 ????

....................................


Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load

'Select the current year in the ComboBox
ComboBox_YEAR.SelectedIndex = 0I
For Counter As Integer = 0I To ComboBox_YEAR.Items.Count - 1I
If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
Next Counter
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Here's the error.
Also I noticed that during runtime the combobox.Month collection items were not available in the pull down.
Only the Default of January was there. But when I clicked the pull down there were no months to choose from.
vbdotnet-passing-gobutton-1-25-2016.jpg
 

Attachments

Last edited:

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,522
Location
Lansing, MI; USA
Programming Experience
10+
Hi,
I noticed YearStr needs to be declared.

Dim YearStr As String ????
YearStr = 2015 ????

....................................


Private Sub REPORT_monthly_Procurement_goods_Load(sender As Object, e As EventArgs) Handles Me.Load

'Select the current year in the ComboBox
ComboBox_YEAR.SelectedIndex = 0I
For Counter As Integer = 0I To ComboBox_YEAR.Items.Count - 1I
If ComboBox_YEAR.Items(Counter).ToString = YearStr Then ComboBox_YEAR.SelectedIndex = Counter
Next Counter
Yep, I forgot to declare YearStr:
Dim YearStr As String = DateTime.Now.Year.ToString()
Here's the error.
Also I noticed that during runtime the combobox.Month collection items were not available in the pull down.
Only the Default of January was there. But when I clicked the pull down there were no months to choose from.
You'll need to fill the months combobox with all of the months, and the years too, maybe a Stored Procedure that returns all the years that are present in the database?
 

cacaoguy

Member
Joined
Dec 30, 2015
Messages
13
Programming Experience
5-10
Yep, I forgot to declare YearStr:
Dim YearStr As String = DateTime.Now.Year.ToString()
You'll need to fill the months combobox with all of the months, and the years too, maybe a Stored Procedure that returns all the years that are present in the database?
Omg Juggalo,

THAT's IT !!!!!!

You've done it!!!!!

:highly_amused: :highly_amused: I am so grateful to you for all of your help, and especially your patience. :highly_amused: :highly_amused:
 

Attachments

Top Bottom