need urgent help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deena22
    New Member
    • Nov 2006
    • 8

    #1

    need urgent help

    Hi

    i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet '. The table contain the following fields: 'staffname, stafftype, date, projectname, projectcode and hoursworked' . On my VB 6.0 form, i have got a ' list Box' containing the 'type of staff', for example 'engineer, manager or secretary'. I have got another 'list Box' containing the 'name of projects' . Also i have got 2 textboxes into which the user will enter the 'Start date' and in the other textbox, the user will enter the 'End date'. The system i'm developing should then find the total number of hours worked from the 'start date' to the 'end date' for the item selected in the 'type of staff' List Box and for the item selected in the 'name of project' List Box. For example, if i choose 'engineer' in the first List Box, i choose 'project aaa' in my second List Box, i enter '4/5/06' as 'Start date' and '10/9/06' as 'End Date', then when the user click on the button ''Calculate Hours Worked '' the 'sum of the hours worked' by the 'engineer' on 'project aaa' from '4/5/06' to '10/9/06' should be calculated and be displayed in a textbox.

    Also i have inserted the following codes in my button command:

    Command1_Click( )
    Dim con As New ADODB.Connectio n
    Dim con_string As String
    Dim sql As String
    Dim rs As New ADODB.Recordset
    con_string = ''Provider = Microsoft.Jet.O LEDB.3.51; Data Source = '' & App.Path & '' \ '' & ''timesheet.mdb ; ''
    con.Open con_string
    While Not rs.EOF
    If rs(1) = List1.List(List 1.ListIndex) And rs(3) = List2.List(List 2.ListIndex) And CDate(rs(2)) >= CDate(Text1.Tex t) And CDate(rs(2)) <= CDate(Text2.Tex t)
    Then
    hoursworked = hoursworked + rs(5)
    End If
    rs.Movenext
    Wend
    Text3.Text = hoursworked

    But when i run the program, i get the following error:

    Run time error '3704'
    Operation is not allowed when the object is closed

    When i click on debug, it highlights the following line of codes:
    While Not rs.EOF

    Please, solve this problem for me.
    Thanks
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by deena22
    Code:
    Command1_Click()
    Dim con As New ADODB.Connection
    Dim con_string As String
    Dim sql As String
    Dim rs As New ADODB.Recordset
    con_string = ''Provider = Microsoft.Jet.OLEDB.3.51; Data Source = '' & App.Path & '' \ '' & ''timesheet.mdb; ''
    [B]con.Open con_string
    While Not rs.EOF[/B]  If rs(1) = List1.List(List1.ListIndex) And rs(3) = List2.List(List2.ListIndex) And CDate(rs(2)) >= CDate(Text1.Text) And CDate(rs(2)) <= CDate(Text2.Text) Then
        hoursworked = hoursworked + rs(5)
      End If
      rs.Movenext
    Wend
    Text3.Text = hoursworked
    But when i run the program, i get the following error:
    Run time error '3704' Operation is not allowed when the object is closed

    When i click on debug, it highlights the following line of codes:
    While Not rs.EOF
    You have not created a recordset "rs". You have opened a connection to the database ("con.Open con_string"), but then you didn't do anything with it. You need to open a table, query or whatever, and assign the result to rs.

    Comment

    Working...