![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
This should be an easy one to figure out but I'm not getting it. I've got a form reading data from a table (tblTempTest5Level). I've got a button on the form that when clicked it would update the value of a field (Choice) in the table. I've got it working but it only changes the value in the first record in the table, I want it to change the value of the record that's currently displayed in the form. Here's the code I've got in the OnClick event: Private Sub CmdA_Click() Dim db As Database Dim rec As Recordset Set db = CurrentDb() Set rec = db.OpenRecordset("tblTempTest5Level") rec.Edit rec!choice.Value = "A" rec.Update Refresh End Sub Any help would be appreciated Rob |
#3
| |||
| |||
|
|
google (AT) pinnaclepromos (DOT) com (Rob) wrote in message news:<85d3bc52.0409041310.3918fa9 (AT) posting (DOT) google.com>... This should be an easy one to figure out but I'm not getting it. I've got a form reading data from a table (tblTempTest5Level). I've got a button on the form that when clicked it would update the value of a field (Choice) in the table. I've got it working but it only changes the value in the first record in the table, I want it to change the value of the record that's currently displayed in the form. Here's the code I've got in the OnClick event: Private Sub CmdA_Click() Dim db As Database Dim rec As Recordset Set db = CurrentDb() Set rec = db.OpenRecordset("tblTempTest5Level") rec.Edit rec!choice.Value = "A" rec.Update Refresh End Sub Any help would be appreciated Rob I think that you code will only deal with the first record because you haven't set up a loop What you probably need is this. If rec.RecordCount rec.MoveFirst Do Until rec.EOF rec.Edit rec!choice.Value = "A" rec.Update rec.MoveNext Loop End If The 'If' Statement checks to see if there is anything to do. You'd get an error message if the table was empty otherwise. You then go to the first record and update it before moving on to the next one. The process keeps looping until you reach the end of file (EOF) Hope this works. Geoff Goddard |
![]() |
| Thread Tools | |
| Display Modes | |
| |