Results 1 to 12 of 12

Thread: [RESOLVED] Whats wrong with this code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Resolved [RESOLVED] Whats wrong with this code

    Hi

    Please can someone tell me what is wrong with this code, it id for my data report that is connected to a DataEnviroment, i use an access database and i the report is working but i am trying to report only on customer names that match the current date, but i keep getting errors.


    VB Code:
    1. vb

    Private Sub DataReport_Initialize()
    Dim MyConn As ADODB.Connection
    Dim MyRecSet As ADODB.Recordset
    Dim sSQL As String
    Set MyConn = New ADODB.Connection
    Set MyRecSet = New ADODB.Recordset
    MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\quick-res\data\data.mdb;"
    MyConn.Open
    sSQL = "SELECT [Customer Name] FROM Guests Where [Arrival Date] = #" & Format(Date, "yyyy-mm-dd") & "#"

    MyRecSet.Open sSQL, adOpenStatic, adLockReadOnly

    Set DataReport1.DataSource = MyRecSet

    MyConn.Close
    MyRecSet.Close


    End Sub

    Please can someone advise me.

    Many thanks

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Whats wrong with this code

    What is the description of the error are you getting and in what line does the error occurs?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    Hi Dee-U

    MyRecSet.Open sSQL, adOpenStatic, adLockReadOnly

    In that line i get "Arguments are of the wrong type or are out of acceptable range"
    then if i take that line out then here

    MyConn.Close
    MyRecSet.Close

    i get "Not allowed when object is Closed".

    Many thanks

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Whats wrong with this code

    In the 2nd argument it should be the connection object right?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    Addicted Member mabbas110's Avatar
    Join Date
    Oct 2005
    Location
    Karachi , Pakistan
    Posts
    172

    Re: Whats wrong with this code

    the correct statement is

    MyRecSet.Open sSQL,connectionSQL, adOpenStatic, adLockReadOnly

    here connectionSQL must be the connection object which u r using for ur project
    Thanks and Regards,

    Muhammad Abbas

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    Hi

    Thank you for the advice, i am fimiliar with vb but very new to sql statements, i still get an error "Arguments are of the wrong type or are in conflict with one another"

    Private Sub DataReport_Initialize()
    Dim MyConn As ADODB.Connection
    Dim MyRecSet As ADODB.Recordset
    Dim sSQL As String
    Set MyConn = New ADODB.Connection
    Set MyRecSet = New ADODB.Recordset
    MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\quick-res\data\data.mdb;"
    MyConn.Open
    sSQL = "SELECT [Customer Name] FROM Guests Where [Arrival Date] = #" & Format(Date, "yyyy-mm-dd") & "#"

    MyRecSet.Open sSQL, connectionSQL, adOpenStatic, adLockReadOnly

    Set DataReport1.DataSource = MyRecSet

    MyConn.Close
    MyRecSet.Close


    End Sub

    Would this be the correct way to pull a report only showing names that match the current date or is there another way.

    Many thanks

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    I was also wandering about something, the datareport is already connected to the dataEnvironment, and now i code the connection again, could this be causing the problem, i am really confused as to how i should do this.

    Many thanks

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Whats wrong with this code

    The variable ConnectionSQL has not been declared and its value has not been set. You open a Connection Object so use it.

    MyRecSet.Open sSQL, MyConn, adOpenStatic, adLockReadOnly

    Don't Close the Connection or the Recordset object. The DataReport is still using them.

    I would remove the DataEnvironment connection from the DataReport.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    Hi BruceVde

    Thank you for the reply, i have tried removing the dataEnvironment, i have fields in the report, so now when i run it i get an error "Cant find customer name field" as this was put there by the data environment. Its rather confusing

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Whats wrong with this code

    Remove/Delete the report from the project and start over.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    Thanks BruceVde

    I'll test it out this evening, and let you know

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Whats wrong with this code

    Hi BruceVde

    Thank you, you are right the DataEnvironment, causes problems. Once it was deleted the report works like a charm. Thank you once again.

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