Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Posts
    52

    Unanswered: edit query[urgebt]

    i know a lil bithow to use the edit query.
    but its not working, it says object variable or with block variable not set.
    actually this is wat i want to do.

    Private Sub cmd_Update_Click()
    rs.Edit
    rs.Fields(0) = txt_date
    rs.Fields(1) = txt_Us
    rs.Fields(2) = txt_Ds
    rs.Fields(3) = txt_Us - txt_Ds
    rs.Fields(4) = "Data"
    rs.Update


    End Sub

    Private Sub Form_Load()

    Listmem.ColumnHeaders.Clear
    Listmem.ColumnHeaders.add , , " ", 0
    Listmem.ColumnHeaders.add , "date", "Date", 1200, lvwColumnRight
    Listmem.ColumnHeaders.add , "u_s", "Upstream", 1200, lvwColumnLeft
    Listmem.ColumnHeaders.add , "d_s", "Downstream", 1200, lvwColumnRight
    Listmem.ColumnHeaders.add , "res", "Reserved", 1200, lvwColumnLeft
    Listmem.ColumnHeaders.add , "com", "Comments", 1000, lvwColumnLeft

    Set rs = CurrentDb.OpenRecordset("select * from sukkur where Comments <> 'Data';")


    While Not rs.EOF
    Set li = Listmem.ListItems.add
    li.SubItems(1) = rs.Fields(0)
    li.SubItems(2) = rs.Fields(2)
    li.SubItems(3) = rs.Fields(1)
    li.SubItems(4) = rs.Fields(3)
    li.SubItems(5) = rs.Fields(4)


    rs.MoveNext
    Wend

    End Sub

    Private Sub Listmem_Click()
    txt_date = Listmem.SelectedItem.SubItems(1)
    txt_Us = Listmem.SelectedItem.SubItems(2)
    txt_Ds = Listmem.SelectedItem.SubItems(3)
    End Sub

    i want the clicked sub items to be updated. so wat to do
    Last edited by waqas; 02-20-03 at 13:14.

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    I assume you are using a class module level variable for rs. When you run through the Form_Load you move the cursor through the recordset until you hit it's end. When you hit the command button the recordset it STILL at EOF thus you can't edit it. If you want to update the entry in the list user has selected you need to move the cursor to the correct record before editing, thus:

    Private Sub cmd_Update_Click()

    if Listmem.ListIndex = -1 then exit sub 'do nothing when nothing is selected

    rs.MoveFirst
    rs.Move Listmem.ListIndex

    rs.Edit
    rs.Fields(0) = txt_date
    rs.Fields(1) = txt_Us
    rs.Fields(2) = txt_Ds
    rs.Fields(3) = txt_Us - txt_Ds
    rs.Fields(4) = "Data"
    rs.Update


    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •