Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
works fine, i now need to be able to update the same recordset feilds
on a seperate userform, do you have any exampleas of this please?? The following code uses the same UserForm. With a seperate UserForm, you would still need a control such as a ListBox to see what is in Table1. I added 2 controls (CommandButton1 and TextBox1) that allow changing the Age field in Table1. Note that most of the code supplied earlier has been moved. Hth, Merjet Private db As Database Private Sub CommandButton1_Click() Dim rs As Recordset Dim bFound As Boolean If TextBox1 < "" And ListBox1.ListIndex -1 Then Set rs = db.OpenRecordset("Table1") rs.MoveFirst Do With ListBox1 ' if Table1 has primary key, need only ' check for match with primary field If rs("Name") = .List(.ListIndex, 0) And _ rs("Age") = CInt(.List(.ListIndex, 1)) And _ rs("SDate") = CDate(.List(.ListIndex, 2)) And _ rs("Pay") = CInt(.List(.ListIndex, 3)) Then rs.Edit rs("Age") = CInt(TextBox1) rs.Update bFound = True End If End With rs.MoveNext Loop Until rs.EOF Or bFound = True End If Set rs = Nothing FillListBox1 End Sub Private Sub UserForm_Activate() Set db = OpenDatabase("C:\temp\db1.mdb") FillListBox1 End Sub Private Sub UserForm_Deactivate() db.Close Set db = Nothing End Sub Private Sub FillListBox1() Dim rs As Recordset Dim Sql As String Sql = "SELECT * FROM Table1 WHERE " _ & "Name = " & Chr(34) & "Smith" & Chr(34) Set rs = db.OpenRecordset(Sql) ListBox1.Clear With rs If Not .BOF Then .MoveFirst While Not .EOF With ListBox1 .AddItem rs("Name") .List(.ListCount - 1, 1) = rs("Age") .List(.ListCount - 1, 2) = rs("SDate") .List(.ListCount - 1, 3) = rs("Pay") End With .MoveNext Wend End With Me.Repaint Set rs = Nothing End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
userform listbox cannot get listbox.value to transfer back to main sub | Excel Programming | |||
Populate userform listbox from access db | Excel Programming | |||
Initialize Userform, Populate Listbox, Dynamic RowSource? | Excel Programming | |||
Populate a ListBox | Excel Programming | |||
populate listbox | Excel Programming |