I have a main form and a sub form of which I have linked through the child and master fields
I want to obtain a value from the sub form and place it in the main form.
In my Main form I have a field txtRiskMatScore and I want the value from the field txtScoreRating in my sub form to be assigned to that field.
The Sub form obviously can have many records pertaining to the record in the main form, so in my sub form there is a date field for each record in the sub form.
So based on the latest date of a record pertaining to the record in the main form I want the value in txtScoreRating control in the sub form to be assigned to the txtRiskMatScore control in the main form.
The code below find the latest date in the underlying query, but it assigns the value to every record in the main form, which is not what I want to do, I want it to only assign the value if the records in both the main form and sub form are a match:
Code Start- :
' Get the latest date from the subform's record source
latestDate = Nz(DMax("dtmDateOfReview", "qryPreferredSupplierOver10000RiskMatrix"), 0)
' Get the value for that latest date
latestValue = Nz(DLookup("lngRiskScore", "qryPreferredSupplierOver10000RiskMatrix", _
"dtmDateOfReview = #" & Format(latestDate, "dd\/mm\/yyyy") & "#"), "")
' Assign to control on main form
Me.txtRiskMatScore = latestValue
End Code
I'm thinking that I need encapsulate the above code in an IF Statement something like below (which isn't working)
Code Start - :
If [Forms]![ frmPreferredSuppliersListOver10000]![Me.txtSupplierIDMain] = [Forms]![ frmPreferredSupplierOver10000RiskMatrix]![txtSupplierSub] Then
' Get the latest date from the subform's record source
latestDate = Nz(DMax("dtmDateOfReview", "qryPreferredSupplierOver10000RiskMatrix"), 0)
' Get the value for that latest date
latestValue = Nz(DLookup("lngRiskScore", "qryPreferredSupplierOver10000RiskMatrix", _
"dtmDateOfReview = #" & Format(latestDate, "dd\/mm\/yyyy") & "#"), "")
' Assign to control on main form
Me.txtRiskMatScore = latestValue
Else
End
End If
End Code
I'm clearly getting something wrong, but I'm struggling to work out what it is, any assistance would be appreciated.
Kind Regards
John
I want to obtain a value from the sub form and place it in the main form.
In my Main form I have a field txtRiskMatScore and I want the value from the field txtScoreRating in my sub form to be assigned to that field.
The Sub form obviously can have many records pertaining to the record in the main form, so in my sub form there is a date field for each record in the sub form.
So based on the latest date of a record pertaining to the record in the main form I want the value in txtScoreRating control in the sub form to be assigned to the txtRiskMatScore control in the main form.
The code below find the latest date in the underlying query, but it assigns the value to every record in the main form, which is not what I want to do, I want it to only assign the value if the records in both the main form and sub form are a match:
Code Start- :
' Get the latest date from the subform's record source
latestDate = Nz(DMax("dtmDateOfReview", "qryPreferredSupplierOver10000RiskMatrix"), 0)
' Get the value for that latest date
latestValue = Nz(DLookup("lngRiskScore", "qryPreferredSupplierOver10000RiskMatrix", _
"dtmDateOfReview = #" & Format(latestDate, "dd\/mm\/yyyy") & "#"), "")
' Assign to control on main form
Me.txtRiskMatScore = latestValue
End Code
I'm thinking that I need encapsulate the above code in an IF Statement something like below (which isn't working)
Code Start - :
If [Forms]![ frmPreferredSuppliersListOver10000]![Me.txtSupplierIDMain] = [Forms]![ frmPreferredSupplierOver10000RiskMatrix]![txtSupplierSub] Then
' Get the latest date from the subform's record source
latestDate = Nz(DMax("dtmDateOfReview", "qryPreferredSupplierOver10000RiskMatrix"), 0)
' Get the value for that latest date
latestValue = Nz(DLookup("lngRiskScore", "qryPreferredSupplierOver10000RiskMatrix", _
"dtmDateOfReview = #" & Format(latestDate, "dd\/mm\/yyyy") & "#"), "")
' Assign to control on main form
Me.txtRiskMatScore = latestValue
Else
End
End If
End Code
I'm clearly getting something wrong, but I'm struggling to work out what it is, any assistance would be appreciated.
Kind Regards
John