4 Replies - 1073 Views - Last Post: 15 September 2011 - 07:56 AM Rate Topic: -----

#1 messirayn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-September 11

list view doesnot updates after a data is saved.

Posted 09 September 2011 - 11:59 AM

i need to know why my listview doesnot updates itself after a data is saved in the database. textfield and command button are in one form and the list view is in another form.the list view updates only after the program is exited and then rerun.
i am new to visual basic so any help will be appreciated
here is my code
form1...
  Public Sub cmdsave_Click()
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sraynh\Desktop\studdetail\database\studentinfo.mdb;Persist Security Info=False"
cn.Open
Set rs = New ADODB.Recordset
rs.Open "select * from tblpersonalinfo where id like'" & txtfirstname.Text & "%';", cn, adOpenKeyset, adLockOptimistic
If txtfirstname.Text = rs!ID Then
MsgBox "file already exists"
Else
With rs
    .AddNew
    !ID = txtfirstname.Text
    !firstname = txtlastname.Text
    !lastname = txtdob.Text
    !dob = txtage.Text
    !age = txtsex.Text
    !sex = txtcourse.Text
    !course = txtsem.Text
    !sem = txtcontact.Text
    !contactno = txtaddress.Text
    !address = txtreligion.Text
    !religion = txtfname.Text
    !fname = txtfoccupation.Text
    !foccupation = txtfcontact.Text
    !fcontact = txtmname.Text
    !mname = txtmoccupation.Text
    !moccupation = txtmcontact.Text
    !mcontact = Text17.Text
    MsgBox "saved"
    rs.MoveNext
    rs.Close
    Set rs = Nothing
    End With
    End If
    Form7.list_records
    
End Sub 



and form2...
  Public Sub list_records()
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sraynh\Desktop\studdetail\database\studentinfo.mdb;Persist Security Info=False"
cn.Open
Set rs = New ADODB.Recordset
rs.Open "select * from tblpersonalinfo", cn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
lv1.ListItems.clear
rs.MoveFirst
Do While Not rs.EOF
Set Item = lv1.ListItems.Add(, , rs!ID)
Item.SubItems(1) = rs!firstname
Item.SubItems(2) = rs!lastname
Item.SubItems(3) = rs!dob
Item.SubItems(4) = rs!age
Item.SubItems(5) = rs!sex
Item.SubItems(6) = rs!course
Item.SubItems(7) = rs!sem
Item.SubItems(8) = rs!contactno
Item.SubItems(9) = rs!address
Item.SubItems(10) = rs!religion
Item.SubItems(11) = rs!fname
Item.SubItems(12) = rs!foccupation
Item.SubItems(13) = rs!fcontact
Item.SubItems(14) = rs!mname
Item.SubItems(15) = rs!moccupation
Item.SubItems(16) = rs!mcontact
rs.MoveNext
Loop
Else
lv1.ListItems.clear
End If
Set rs = Nothing
End Sub  



thanks ...

This post has been edited by AdamSpeight2008: 09 September 2011 - 12:02 PM
Reason for edit:: Please the correct codes tags


Is This A Good Question/Topic? 0
  • +

Replies To: list view doesnot updates after a data is saved.

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 547
  • View blog
  • Posts: 2,904
  • Joined: 19-May 09

Re: list view doesnot updates after a data is saved.

Posted 09 September 2011 - 11:16 PM

Have a look at this, in particular the example given: http://msdn.microsof...6(v=VS.85).aspx . Now, I've never tried to see if doing a MoveNext will update the record as you appear to believe. I've always used the Update method, as seen in the example. There are times when you need to use it and times when you don't, and the doc is confusing as to what types of cursors need it. But a good indicator that you need it is that you aren't getting the record posted to your database.
Was This Post Helpful? 0
  • +
  • -

#3 messirayn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-September 11

Re: list view doesnot updates after a data is saved.

Posted 10 September 2011 - 07:25 AM

View PostBobRodes, on 09 September 2011 - 11:16 PM, said:

Have a look at this, in particular the example given: http://msdn.microsof...6(v=VS.85).aspx . Now, I've never tried to see if doing a MoveNext will update the record as you appear to believe. I've always used the Update method, as seen in the example. There are times when you need to use it and times when you don't, and the doc is confusing as to what types of cursors need it. But a good indicator that you need it is that you aren't getting the record posted to your database.

thanks for the link. this is a different approach to adding data to my database but certainly helpful. my problem is that
the textboxes and the save button is in one form and the list view in another form. so i need to update the latter form to update the listview when i press the save button in the first form.
p.s the link was very helpul. i am going to use the code in next form. Thanks again
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 547
  • View blog
  • Posts: 2,904
  • Joined: 19-May 09

Re: list view doesnot updates after a data is saved.

Posted 14 September 2011 - 05:34 PM

The way that you do that is reference the other form.

Every time you reference a control on your form, e. g. Text1.Text = "Hello" you are implicitly referencing the form too. So this is equivalent to the last: Me.Text1.Text = "Hello". If you are on Form1, and want to reference ListView1 on Form2 without making Form2 the current form, you just have to specifically reference Form2, e. g.: Form2.ListView.ListItems.Add "Whatever".
Was This Post Helpful? 0
  • +
  • -

#5 messirayn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-September 11

Re: list view doesnot updates after a data is saved.

Posted 15 September 2011 - 07:56 AM

View PostBobRodes, on 14 September 2011 - 05:34 PM, said:

The way that you do that is reference the other form.

Every time you reference a control on your form, e. g. Text1.Text = "Hello" you are implicitly referencing the form too. So this is equivalent to the last: Me.Text1.Text = "Hello". If you are on Form1, and want to reference ListView1 on Form2 without making Form2 the current form, you just have to specifically reference Form2, e. g.: Form2.ListView.ListItems.Add "Whatever".
thanks for the tip i finally found the solution.

This post has been edited by BobRodes: 16 September 2011 - 03:40 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1