Results 1 to 6 of 6

Thread: [RESOLVED] dtpicker,access Parameter query,report error

Threaded View

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Resolved [RESOLVED] dtpicker,access Parameter query,report error

    Good day to all!

    I am new to this forum and i have an ongoing project in vb 6.0 that is simple POS system. I have not completed this project yet.

    I am creating a form called sales report with two dtpicker, and three command buttons. One dtpicker is for selecting a starting date and the second one is for selecting an ending date. The values from these dtpicker controls will be sent to a parameter query in MS Access 2000. I have tried several codes and have not been successful. The data report should access the parameter query in the database and will be viewed when the user choose the button cmdViewReport.

    My parameter query in ms access has the following SQL Code:
    This code will prompt the user to enter start and end dates to generate a sales report within the date range
    The query name is qrySalesReport

    SELECT OrderMain.OrderId, OrderMain.OrderDate, orderdet.Item_Code, Item.Item_Name, Item.Item_Price, Item.Item_Unit, orderdet.Q_Ord, [Item_Price]*[Q_Ord] AS amount
    FROM (Customer INNER JOIN OrderMain ON Customer.Cus_ID = OrderMain.Cus_ID) INNER JOIN (Item INNER JOIN orderdet ON Item.Item_Code = orderdet.Item_Code) ON OrderMain.OrderId = orderdet.OrderID
    WHERE (((OrderMain.OrderDate) Between [Starting Date] And [Last Date]));


    My code in sales report form with errors
    VB Code:
    1. Option Explicit
    2. Dim s_date As Date
    3. Dim e_date As Date
    4. Dim cnn As New ADODB.Connection
    5. Dim cmd As New ADODB.Command
    6. Dim prm1 As New ADODB.Parameter
    7. Dim prm2 As New ADODB.Parameter
    8. Dim rst As New ADODB.Recordset
    9.  
    10. Private Sub cmdExit_Click()
    11.     Set rst = Nothing
    12.     Set cnn = Nothing
    13.     Unload Me
    14. End Sub
    15.  
    16. 'this button will send the values from dtpicker controls to
    17. 'access parameter query
    18. Private Sub cmdProcessReport_Click()
    19.    
    20.     s_date = FormatDateTime(dtStart.Value, vbShortDate)
    21.     e_date = FormatDateTime(dtEnd.Value, vbShortDate)
    22.    
    23.     Print s_date & " " & e_date
    24.            
    25.     'With cmd
    26.      '  .ActiveConnection = cnn 'predefined connection object
    27.      '  .CommandType = adCmdText
    28.      '  .CommandText = "select * from qrySalesReport"
    29.      '  .Parameters(0) = DateValue(s_date)
    30.      '  .Parameters(1) = DateValue(e_date)
    31.      '   Set rst = cmd.Execute
    32.    ' End With
    33.    
    34.     With cmd
    35.        Set .ActiveConnection = cnn
    36.        .CreateParameter "[Starting Date]", adDate, , , DateValue(s_date)
    37.        .CreateParameter "[Last Date]", adDate, , , DateValue(e_date)
    38.         .CommandType = adCmdStoredProc
    39.         .CommandText = "Select * from qrySalesReport where [OrderDate] Between" & DateValue(s_date) & "And " & DateValue(e_date)
    40.              '.CommandText = "qrySalesReport"
    41.         Set rst = cmd.Execute
    42.     End With
    43.      
    44.    cmdViewReport.Enabled = True
    45. End Sub
    46.  
    47. Private Sub cmdViewReport_Click()
    48.    
    49.     With rptSalesReport
    50.         .WindowState = vbMaximized
    51.         .Caption = "Sales Report"
    52.     End With
    53.     rptSalesReport.Show
    54. End Sub
    55.  
    56. Private Sub Form_Load()
    57.       cmdViewReport.Enabled = False
    58.       cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    59.       "Data Source=d:\POSSample\Orders.mdb;"
    60. End Sub

    Hoping for any response.........











    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Dec 7th, 2005 at 07:01 AM.

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