انا اشتغلت بالمثال اللى كنت بعتالك رابط بتاعه
وغيرت بس اسماء الحقول زى اللى عندى ودا الكود الموجود
عايزه أقوله يشتغل على نفس
ID
اللى انا واقفه عنده فى ال فورم
Public Function Concat(F_Name, P_Name)
On Error GoTo err_Concat
'F_Name = Field Name
'P_Name = Person Name
Dim rst As DAO.Recordset
Dim RC As Integer
Dim i As Integer
Dim Add_Me As String
Dim strSQL As String
'do the query SQL for this Field name ONLY
strSQL = "Select [" & F_Name & "] From [New_Request] Where [PName]= '" & P_Name & "'"
Set rst = CurrentDb.OpenRecordset(strSQL) 'make the Recordset in memory
rst.MoveLast: rst.MoveFirst: RC = rst.RecordCount
'loop through the Records
For i = 1 To RC
'ONLY add this value if we didn't add it before
If InStr(Add_Me, rst(F_Name)) = 0 Then
Add_Me = Add_Me & ", " & rst(F_Name) 'Concatenate these values
End If
rst.MoveNext
Next i
Concat = Mid(Add_Me, 3) 'remove the initial comma
Exit_Concat:
rst.Close: Set rst = Nothing
Exit Function
err_Concat:
If Err.Number = 3021 Then
'no data
Concat = ""
Resume Exit_Concat
ElseIf Err.Number = 3061 Then
'too few parameters, expected xx
'this error occurs when trying to run a query which needs its parameters from a Form,
'the Form should be open with the parameter, then this code take the values properly
Dim qdf As DAO.QueryDef
Dim prm As Parameter
' For Each qdf In CurrentDb.QueryDefs
' If qdf.Name = "NewQueryDef" Then
' CurrentDb.QueryDefs.Delete "NewQueryDef"
' Exit For
' End If
' Next
Set qdf = CurrentDb.CreateQueryDef("NewQueryDef", strSQL)
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset)
CurrentDb.QueryDefs.Delete "NewQueryDef"
Resume Next
Else
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Function