I've been stumped on what to write. I think there are several issues that need/should be addressed - one of which is the table structures.
By this I mean you have tables "tblBorrower" (I'm guessing), "tblLoan" and "tblLoanHistory". In each table there appears to be fields for "[Borrower ID]", "Forename" and "Surname". The same data is being stored in 3 different tables! It is unnecessary - the fields "Forename" and "Surname" should ONLY be in the borrower table.
Not sure what query "qryCheckIn" is used for......
I would not be deleting and appending records - I would use the "flag" approach that Micron suggested.
As for the code for the message box, I came up with a blend of my suggestion and Paul's.
I don't know if [Forms]![frmCheckIn]![BarcodeCI] is TEXT of a NUMBER - I guessed a number.
Try this in a COPY of your dB:
Code:
'------------------------------------------------------------
' Command12_Click
'
'------------------------------------------------------------
Private Sub Command12_Click()
On Error GoTo Command12_Click_Err
Dim strUserFName As String
Dim strUserSName As String
' if [BarcodeCI] is numeric
strUserFName = DLookup("Forename", "tblLoan", "[Barcode Number] = " & [Forms]![frmCheckIn]![BarcodeCI])
strUserSName = DLookup("Surname", "tblLoan", "[Barcode Number] = " & [Forms]![frmCheckIn]![BarcodeCI])
'if [BarcodeCI] is Text, uncomment the following two lines and comment out the two DLookups above
' strUserFName = DLookup("Forename", "tblLoan", "[Barcode Number] = '" & [Forms]![frmCheckIn]![BarcodeCI] & "'")
' strUserSName = DLookup("Surname", "tblLoan", "[Barcode Number] = '" & [Forms]![frmCheckIn]![BarcodeCI] & "'")
DoCmd.OpenQuery "qryCheckInAppend", acViewNormal, acEdit
DoCmd.OpenQuery "AvailableYesUpdate", acViewNormal, acEdit
DoCmd.OpenQuery "qryCheckInDelete", acViewNormal, acEdit
Beep
MsgBox "Thank you " & strUserFName & " " & strUserSName & vbCrLf & "Book successfully returned."
DoCmd.Close acForm, "frmCheckIn"
DoCmd.OpenForm "frmCheckIn", acNormal, "", "", , acNormal
Command12_Click_Exit:
Exit Sub
Command12_Click_Err:
MsgBox Error$
Resume Command12_Click_Exit
End Sub