Hi, there.
Well, it requires some definite table design - the table on "many" side of relationship has to have AutoNumber field.
Below is working example.
Tables: tblMaster
keyMasterID Autonumber(Long), PK
......
tblChild
keyChildID Autonumber(Long, Increment), PK
keyMasterID FK(tblMaster)
.........
Code module: -
Public Function EnumRecords(varPK As Variant, varFK As Variant) As Variant
-
-
'declares variable which content will be preserved between calls
-
Static lngCounter As Long
-
-
If IsNull(varPK) Or IsNull(varFK) Then Exit Function
-
-
'reset counter if the value of tblChild.keyChildID
-
' is the minimum for given tblChild.keyMasterID
-
If DMin("keyChildID", "tblChild", "keyMasterID=" & varFK) = varPK Then _
-
lngCounter = 0
-
-
lngCounter = lngCounter + 1
-
EnumRecords = lngCounter
-
-
End Function
-
Queries: qryChild -
SELECT tblChild.keyChildID, tblChild.keyMasterID, tblChild.txtChild, "Element " & EnumRecords(tblChild.keyChildID,tblChild.keyMasterID) AS txtElNo
-
FROM tblChild;
-
Forms: frmMaster
RecordSource: tblMaster
Controls: frmChild as subform
frmChild
RecordSource: qryChild
Controls: txtElNo as TextBox - > ControlSource: qryChild.txtElNo
Regards,
Fish