Question : Form and subform referencing the same table


I have a form (frmConvoyTracking) which is a single entry form and want to load a subform (subfrmConvoyTracking) onto it.  Both forms reference the same table (tblMain).  The primary key of tblMain is intMainID.  I want the ability to scroll through the subform and each time a new row is highlighted, the corresponding fields will display in the main form.  When I dropped subfrmConvoyTracking onto frmConvoyTracking, I did not establish a relationship between the two forms.  Users will not be able to make changes to the data in the subform, only the main.  I tried the following code in subfrmConvoyTracking:

Private Sub Form_Current()

  Forms!frmConvoyTracking.RecordSetClone.FindFirst "intMainID = " & Me!intMainID & ""
  Forms!frmConvoyTracking.Bookmark = Forms!frmConvoyTracking.RecordSetClone.Bookmark

End Sub

I'm sure someone has done this before, I just can't find it in the solution database.

Thanks.

Answer : Form and subform referencing the same table

write the following code at form 'subfrmConvoyTracking' on current events

Private Sub Form_Current()
    Dim rs As Object

    Set rs = Forms!frmConvoyTracking.Recordset.Clone
    rs.FindFirst "[intMainID]= " & Str(Nz(intMainID, 0))
    If Not rs.EOF Then Forms!frmConvoyTracking.Bookmark = rs.Bookmark

End Sub

for Users will not be able to make changes to the data in the subform
you change the subform property as

Allow Edits=false
Allow Deletions=false
Allow Additions =false

thanks

Random Solutions  
 
programming4us programming4us