Requery!

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
 
D

Dirk Goldgar

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top