MMSI is a string so why is ID declared as integer type? Don't really need this variable.
The ShipSearch = "" line could be outside the If Then block.
The first Else is not necessary.
Code:
With Me
If Nz(DLookup("MMSI", "tblShip", "MMSI='" & .ShipSearch & "'"), "") = "" Then
' doesn't exist
If MsgBox("Ship is not in database. Add as new ship?", vbYesNo + vbQuestion, "Add New?") = vbYes Then
' add as new ship
DoCmd.OpenForm "frmShipData", , , , acFormAdd
Forms!frmShipData!MMSI = .ShipSearch
End If
Else
' Ship exists'
DoCmd.OpenForm "frmShipData", , , "MMSI='" & .ShipSearch & "'"
End If
.ShipSearch = ""
End With
Might want to use ValidationRule and ValidationText properties of textbox to make sure user enters a valid value. Or use a combobox for selecting MMSI value and its NotInList event.
Advise not to use exact same field name in multiple tables. For the MMSI foreign key, consider MMSI_fk.
Note for future, post code between CODE tags to retain indentation and readability. Click # icon on post edit toolbar.