Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requery only shows first record in table 1

Status
Not open for further replies.

BrianLe

Programmer
Feb 19, 2002
229
US
In AC97, I have a form with a subform. The combobox on the mainform has the following event code


Code:
Private Sub cbxTrainNo_AfterUpdate()
Me.tblTrainOrderSubform.Form.Requery
End Sub

When cbxTrainNo is updated with the TrainNo of the first record in tblTrainOrder, the subform shows the desired info from table TrainOrder. However, when any other TrainNo is selected, then no info is in the subform. If I delete the first record in TrainOrder, then select what was the second TrainNo, the info for what is now the first TrainNo shows in the subform.

Why doesn't the subform update when a TrainNo other than the first in the table TrainOrder is selected?

Thanks,

Brian
 
First, the requery is doing what you are asking it to do - start showing the records in the subform FROM THE START. You didn't tell it to only find records related to the combobox.
Next, it sounds like you didn't turn on Referential Integrity. You deleted a parent but still have child records. These are called orphans. Very bad.
You didn't say how you created the form/subform so I don't know what you did. However, I created two forms. I opened the main one in design view. Then I used the subform/subreport wizard to add the subform. Then I Deleted the TrainNo field and create a combobox using the third option in the combobox wizard. Everything works. I select a TrainNo, the main form shows the info and the subform changes also. You don't need any coding.
 
Thanks fneily. What you suggested got me going in the right direction, and now I think I've got it.

I didn't mention in my first post that the Row Source of the selection box was a query so I could show the details of TrainID, i.e. TrainYear and TrainNo. I mistakenly used TrainNo instead of TrainID in my original post. I changed the combobox to a listbox.

Thanks again,

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top