Option Compare Database Option Explicit Public Function fnUpdateOrderRef() As Boolean Dim sCustRef As String Dim sDelPostcode As String Dim sOrderRef As String Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("select autoId from tbl_empdets where smesos_id=""" & user & """;") rs.MoveFirst sCustRef = rs!CustRef sDelPostcode = rs!DelPostcode sOrderRef = rs!OrderRef Next_Record: rs.MoveNext If rs.EOF Then Exit Function If rs!CustRef = sCustRef And rs!DelPostcode = sDelPostcode Then rs.Edit rs!OrderRef = sOrderRef rs.Update Else sCustRef = rs!CustRef sDelPostcode = rs!DelPostcode sOrderRef = rs!OrderRef End If GoTo Next_Record End Function Sub test() Call fnUpdateOrderRef End Sub |