I have a subform embedded in my main form as a datasheet. The subform's data gets populated after I select some filtering criteria and click "search" button. Everything works fine except one control I have in this subform. This is an unbound control and I will set its control source in the subform's onLoad event with values input from other controls of my subform. When I first load the main form and before select anything or click "search" button, the subform is displayed with an empty row of record. However, on the column of my unbound control, it shows as "#ERROR" while others are all blank. I know this will work fine after I do the search and my unbound control data gets populated, but is there anyway I can avoid showing the ugly "#ERROR" in my subform?
Part of my code is here.
Private Sub Form_Load()
Me.text_root_cause_field.ControlSource = "=getLatestRemark([plant], [shipment_no])"
End Sub
Public Function getLatestRemark(plant_code As String, shipment_no As String) As String
Dim db As Database
Dim srRS As Recordset
Set db = CurrentDb
Set srRS = db.OpenRecordset("SELECT TOP 1 root_cause FROM Shipment_Remark" _
& " WHERE plant = '" & plant_code & "'" _
& " AND shipment_no = '" & shipment_no & "'" _
& " ORDER BY update_time DESC", dbOpenDynaset)
If Not srRS Is Nothing Then
If Not srRS.EOF Then
getLatestRemark = srRS!root_cause
srRS.Close
Set srRS = Nothing
End If
Else
getLatestRemark = ""
End If
db.Close
Set db = Nothing
End Function
These are codes for my subform. text_root_cause_field is the unbound field I am talking about. Its control source depends on two other bound fields - [plant] and [shipment_no]. The field [plant] and [shipment_no], however, are only bound at run time after the user clicks search button in the main form and the subform's record source is set.
Thanks for the help.