I have a form which has a listbox with 4 values
Active, Inactive, Win, Loss
I have 4 tables with the above values ie Active,
Inactive, Win, Loss. Only the table Active has records.
I have created a form for this table. Depending upon the
selection of the listbox I want to move the current record
from Active to other tables. For eg if the change is from
Active -> Inactive then the current record gets moved to
Inactive table.
I tried some code.. doesnt work
Private Sub State_Change()
Dim db As Database
Dim rs As Recordset
Dim rstemp As Recordset
Dim X As Variant
i = 0
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblActive")
X = Me.State.Value
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
MsgBox (rs.Fields("State").Value)
If rs.Fields("State").Value = "Inactive" Then
MsgBox (rs.Fields("State").Value)
Set rstemp = db.OpenRecordset("tblInactive")
rstemp.AddNew
Do While i < 19
rstemp.Fields(i) = rs.Fields(i).Value
i = i + 1
Loop
rstemp.Update
rs.Delete
Set rstemp = Nothing
rs.MoveNext
i = 0
End If
Loop
End Sub
Active, Inactive, Win, Loss
I have 4 tables with the above values ie Active,
Inactive, Win, Loss. Only the table Active has records.
I have created a form for this table. Depending upon the
selection of the listbox I want to move the current record
from Active to other tables. For eg if the change is from
Active -> Inactive then the current record gets moved to
Inactive table.
I tried some code.. doesnt work
Private Sub State_Change()
Dim db As Database
Dim rs As Recordset
Dim rstemp As Recordset
Dim X As Variant
i = 0
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblActive")
X = Me.State.Value
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
MsgBox (rs.Fields("State").Value)
If rs.Fields("State").Value = "Inactive" Then
MsgBox (rs.Fields("State").Value)
Set rstemp = db.OpenRecordset("tblInactive")
rstemp.AddNew
Do While i < 19
rstemp.Fields(i) = rs.Fields(i).Value
i = i + 1
Loop
rstemp.Update
rs.Delete
Set rstemp = Nothing
rs.MoveNext
i = 0
End If
Loop
End Sub