First, I'm a beginner in this area. I have a continuous form tied to a query that displays only active records pulled from Table1. Within the form is a textbox that i'd like to use to display information (if it exists) relevant to each active record shown in the continuous form. The query/form displays 15 records. If i add Table2 to query (Table2 is the 'Many' relationship to Table1) and set the relationship such that all records in Table1 are required along with the info in Table 2 (Table2 info is applicable to only 3 Table 1 records) my query/form now displays 18 records...
For example, there are 3 entries in Table 2 that are related to Table 1, Record 2. Current query containing both tables yields three consecutive Table 1, Record 2 entries and if i bind the text box the Table2 data, i have a single item in each text box.
What I'm trying to do is have a single entry for each Table1 record and populate the corresponding text box (or list box) with Table 2 Data.
My code (is ugly) makes a recordsetclone of the form (query) and loads data from Table2. Then two for loops...(not optimal) outer runs through the clone, inner goes through all Table2 records. If a match is found between the compared values, then i make a string from the actual Table2 data I want in the text box. Once inner loop done, if string > 0 then populate text box...
Right now, it will simply put the last string into every text box... Sample code below...be gentle...i know it's ugly
Private Sub Form_Load()
Dim db As Database
Dim rst1, rst2 As Recordset
Dim ftpString As String
Dim frmTemp As Form_sfrmTOLlist
Dim sfrmTOLlistcnt As Integer
Set db = CurrentDb
Set frmTemp = Me.Form
Set rst1 = Me.RecordsetClone
Set rst2 = db.OpenRecordset("tbl_jnc-Tol_ftp")
For x = 1 To .RecordCount
For y = 1 To rst2.RecordCount
If rst2.Fields(0) = .Fields(0) Then
ftpString = ftpString & rst2.Fields(TOL_ID).Value & " "
End If
rst2.MoveNext
Next y
If Len(ftpString) > 0 Then
[Text42].Value = ftpString
Debug.Print (ftpString)
End If
ftpString = ""
rst2.MoveFirst
.MoveNext
Next x
End Sub