G
Gaetan
Hi,
I have a continuous form in which I have, amongst others, a combo box
(cboActivity) and a text box (txtActivityComments). The cboActivity combo box
lets the user select a production activity. Some of these activities requires
the user to enter comments in the txtActivityComments text box.
After comments have been entered in txtActivityComments, the user still has
the possibility to change the chosen activity. If this is done, the
txtActivityComments text box is disabled by the use of a conditional
formating and it's content is cleared witn an AfterUpdate event on the
cboActivity combo box.
After messing around quite a lot with the code (being a newbie with VBA,
especially with recordsets), I have finally got it to work as I wanted,
except from a little problem. When the code runs, after remove the comments
from the txtActivityComments text box, it sets the focus on the first record
of the continuous form, even though the modified record was the fifth one.
How would I adapt my code so that the focus stays on the record that has
been modified? I have a clue that it moves to the first record because of the
requery method but without this, the txtActivityComments text box doesn't get
cleared properly.
Here's my code below...
Private Sub cboActivity_AfterUpdate()
Dim dbMyDB As DAO.Database
Dim rcdProdEntry As DAO.Recordset
Dim lngRcdNum As Long
Dim X As Long
Set dbMyDB = CurrentDb
Set rcdProdEntry = dbMyDB.OpenRecordset("qryProductivity")
lngRcdNum = Me.CurrentRecord
rcdProdEntry.MoveFirst
For X = 1 To lngRcdNum - 1
rcdProdEntry.MoveNext
Next X
Me.Requery
If rcdProdEntry![ActComments] = -1 Then
rcdProdEntry.Edit
rcdProdEntry![Comments] = Null
rcdProdEntry.Update
End If
End Sub
Thanks for any help you can provide me with!
I have a continuous form in which I have, amongst others, a combo box
(cboActivity) and a text box (txtActivityComments). The cboActivity combo box
lets the user select a production activity. Some of these activities requires
the user to enter comments in the txtActivityComments text box.
After comments have been entered in txtActivityComments, the user still has
the possibility to change the chosen activity. If this is done, the
txtActivityComments text box is disabled by the use of a conditional
formating and it's content is cleared witn an AfterUpdate event on the
cboActivity combo box.
After messing around quite a lot with the code (being a newbie with VBA,
especially with recordsets), I have finally got it to work as I wanted,
except from a little problem. When the code runs, after remove the comments
from the txtActivityComments text box, it sets the focus on the first record
of the continuous form, even though the modified record was the fifth one.
How would I adapt my code so that the focus stays on the record that has
been modified? I have a clue that it moves to the first record because of the
requery method but without this, the txtActivityComments text box doesn't get
cleared properly.
Here's my code below...
Private Sub cboActivity_AfterUpdate()
Dim dbMyDB As DAO.Database
Dim rcdProdEntry As DAO.Recordset
Dim lngRcdNum As Long
Dim X As Long
Set dbMyDB = CurrentDb
Set rcdProdEntry = dbMyDB.OpenRecordset("qryProductivity")
lngRcdNum = Me.CurrentRecord
rcdProdEntry.MoveFirst
For X = 1 To lngRcdNum - 1
rcdProdEntry.MoveNext
Next X
Me.Requery
If rcdProdEntry![ActComments] = -1 Then
rcdProdEntry.Edit
rcdProdEntry![Comments] = Null
rcdProdEntry.Update
End If
End Sub
Thanks for any help you can provide me with!