I am attempting to perform some actions based on the current value of fields in the Form.Recordset in the Form.Current event.
An example would be
If Me.RecordSet("LastUpdate") < "#1 Jan 2020#" Then MsgBox "Last year's Comment"
Me.RecordSet could be something like "SELECT ID, LastUpdate, Comment FROM Comment WHERE ID = 12" or it could also return several records, e.g. "SELECT ID, LastUpdate, Comment FROM Comment WHERE ID < 12"
I get the Error 3021: No current record on the above line. It appears that although the Form.Current event has launched and the Me.Recordset Property correctly gives the underlying SQL, the recordset has not been populated yet?
If in the immediate pane when when debugging this line I do Me.Recordset.MoveFirst it then works. But of course, resetting the current record to the first record every time the Form.Current event fires is not the way forward...
It seems strange to me that in the Form.Current event, the Form.Recordset has not yet been populated? Is this right? Any thoughts on the correct way to do what I am trying to do?
The underlying tables are on a MySql server, although that should be irrelevant?
Edit: It appears that the Form.Current event fires 3 times... and only the last time triggers this error. So ignoring the error could be viable, but clearly I'd like to understand why that event is fired 3 times... I will need to look at the calling code.
Still not sure I understand how/why Form.Recordset would become invalidated.
Me.LastUpdate.Value? - AndreForm.Recordset. The form's current record follows its.Recordset- but not the other way around, which is exactly your problem. - Andre