Requery!

  • Thread starter Thread starter Vivian
  • Start date Start date
V

Vivian

I created a combo box which has Requery code (me.requery)
on Afterupdate Action. This code will help me to update
data on a textbox, but it will take me to the first
record. Is there anyway that I can requery and record
still stay the same record?

I also try (me.textbox.requery), but it didn't respond
anything. Please advise.

Vivian
 
Vivian said:
I created a combo box which has Requery code (me.requery)
on Afterupdate Action. This code will help me to update
data on a textbox, but it will take me to the first
record. Is there anyway that I can requery and record
still stay the same record?

I also try (me.textbox.requery), but it didn't respond
anything. Please advise.

Vivian

A requery of the form will always start it over again at the first
record. The solution is to save the primary key of the record you were
on before requerying, and then after requerying position the form to
that record again. Here's a rough, "air code" example:

'----- start of example code -----
Private Sub cboMyCombo_AfterUpdate()

Dim varID As Variant

varID = Me!IDField.Value

Me.Requery

If Not IsNull(varID) Then
Me.Recordset.FindFirst "IDField=" & varID
End If

End Sub
'----- end of example code -----

That's assuming that IDField is a numeric field. If it's text, you have
to enclose the value in quotes; for example,

Me.Recordset.FindFirst "IDField=" & _
Chr(34) & varID & Chr(34)
 
Back
Top