Synchronize Form Data to List Box After Update

R

Ryan

I am using a list box on a form that gets updated with data from a pop-up
form that I created. The information added to the list box is the primary
key for the data listed on the form. I can add the data to the list box, but
when I highlight the newly added number the fields on the form display the
data for the first record in the table. Is there VB code that can be added
to the AfterUpdate event procedure of the list box that would refresh the
table data? Below is what is currently in the AfterUpdate event procedure.

Private Sub List2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FrmNumber] = '" & Me![List2] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
T

tina

sounds like you need to Requery the main form, when the pop-up form is
closed. in the pop-up form's Close event, try something like

Forms!MainFormName.Form.Requery

replace MainFormName with correct name of your main form, of course.

hth
 
R

Ron2006

An alternative way of doing same thing:

1) change the call to the popup to be acDialog
2) add next line of code be me.fieldnamewhichcalledpopup.requery. or
me.requery depending on what caused the call to the popup.

The key is the acDialog which forces the sequence of events.

The advantage here is that then the same popup can be called from
multiple screens which cannot be done if the popup is doing the
requery.

Ron
 
R

Ryan

That work perfectly.

Thanks Tina!
--
Ryan


tina said:
sounds like you need to Requery the main form, when the pop-up form is
closed. in the pop-up form's Close event, try something like

Forms!MainFormName.Form.Requery

replace MainFormName with correct name of your main form, of course.

hth


Ryan said:
I am using a list box on a form that gets updated with data from a pop-up
form that I created. The information added to the list box is the primary
key for the data listed on the form. I can add the data to the list box, but
when I highlight the newly added number the fields on the form display the
data for the first record in the table. Is there VB code that can be added
to the AfterUpdate event procedure of the list box that would refresh the
table data? Below is what is currently in the AfterUpdate event procedure.

Private Sub List2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FrmNumber] = '" & Me![List2] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
T

tina

you're welcome :)


Ryan said:
That work perfectly.

Thanks Tina!
--
Ryan


tina said:
sounds like you need to Requery the main form, when the pop-up form is
closed. in the pop-up form's Close event, try something like

Forms!MainFormName.Form.Requery

replace MainFormName with correct name of your main form, of course.

hth


Ryan said:
I am using a list box on a form that gets updated with data from a pop-up
form that I created. The information added to the list box is the primary
key for the data listed on the form. I can add the data to the list
box,
but
when I highlight the newly added number the fields on the form display the
data for the first record in the table. Is there VB code that can be added
to the AfterUpdate event procedure of the list box that would refresh the
table data? Below is what is currently in the AfterUpdate event procedure.

Private Sub List2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FrmNumber] = '" & Me![List2] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 

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