Why write directly to the table instead of changing the value in the control
on the form?
Perhaps this query is not updatable, so you have no alternative. The example
below is aircode so you will need to debug it. It assumes a numeric primary
key named ID. It saves the value into a variant. After executing your update
query, it finds that record again.
Dim varID as Variant
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
varID = Me.[ID].Value 'Save the primary key value, to find later.
'your execute query here.
Me.Requery 'Requery the form.
With Me.RecordsetClone
If .RecordCount > 0 Then
If IsNull(varID) Then 'Must have been a new record.
RunCommand acCmdRecordsGotoNew
Else 'Find the key value we had before.
.FindFirst "ID = " & varID
If .NoMatch Then
MsgBox "Disappeared."
Else
Me.Bookmark = .Bookmark
End If
End If
End If
End With
Note that if the form is based on a non-updatable recordset and there are no
records, the detail section of yor form will go completely blank, and the
attempt to assign the value of the non-existent text box (line 5) will fail.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
yaya said:
Allen, i have another quation:
I have a form base on this big table i talked about.
from this form i call a vba function that change (by "db.execute" sql
statement) one of the fields in the current record that shown in the form.
to reflect the changes i use: forms![frm1].refresh and as i said it is
very
very slow.
I can't use here ".dirty" because the changes made by the function and not
by the form.
Do you have another way to reflect the changes only to this specific
record
in the form?