View Full Version : Subform Help!


socko139
03-12-2001, 08:41 AM
I have a problem that no one has been able to answer. I've created a form with a tab control. My first form (tab) contains all my main data and a Work center ID. Each subsequent tab contains a subform(which is actually a different table - linked by WC_ID) Here is where it gets tricky. One tab is called systems. Where a WC_ID can contain many systems. What I created was a cross reference table to hold this information. In my main table I have WC_ID and WC_Name. In another table I have Sys_ID and Sys_name. Then I created a cross reference table which contained WC_ID Sys_ID and Sys_Name. So on my subform I can add multiple systems to each WC_ID. When I go into my Systems subform and go through each record(WC_ID) the systems assigned to each WC_ID is shown. I realize this is working because of the code I built in the button...see example:

Private Sub cmd_next_Click()
On Error GoTo Err_cmd_next_Click

DoCmd.GoToRecord , , acNext
Dim source As String
'Reset the values in the list box to display the new entries
source = "SELECT distinct [tbl_systems].[Sys_ID], [tbl_systems].[Sys_Name] FROM tbl_systems, tbl_general_information, tbl_WC_Sys_xref WHERE [tbl_systems].[Sys_ID]=[tbl_WC_Sys_xref].[Sys_ID] And [tbl_WC_Sys_xref].[WC_ID]=" & Me.WC_ID

'Set the source of the listbox to the query you just wrote
lb_assigned.RowSource = source
Exit_cmd_next_Click:
Exit Sub
Err_cmd_next_Click:
MsgBox Err.Description
Resume Exit_cmd_next_Click
End Sub

So again...because of this code my view is refreshed and I can see what systems are assigned.... Now my problem...when I attach this subform to my main form (as a Systems tab)...and on my main form go through each record (Or WC_ID—I do this by clicking the next arrow on the main form)..when I click into the Systems tab....Its only showing the systems for the first WC_ID or record. I have a work around which...honestly is useless. If I go into my systems tab and click the next button which I built(next button on subform which the code above details) WC_ID goes to autonumber ---(This is because I filtered the records here) when I click back on the previous button (Again, same as above code..a button I created on my subform) to get back onto the WC_ID the view refreshes and I can see the systems assigned to that particular WC_ID. I know this is a bit confusing, but can anyone help me...or at least show me how to apply the code I wrote on my subform...behind my main forms Record next button/previous/and search for record button. I hope someone can help me...I feel I've exhausted all my resources except for this. Thanks!!!! Basically when it comes down to it…. Systems assigned are not being refreshed..when I go through each record. They sit on the same systems for the first WC_ID.