HI Micron,
Thanks for your help earlier. Having used the allenbrowne link I have managed to get the data I require however I think there may be a far more efficient way of doing it.
My first query
Code:
SELECT tbl_booking.bookingID, tbl_booking.propertyID, tbl_booking.guestID, (SELECT TOP 1 Dupe.bookingID FROM tbl_booking AS Dupe WHERE Dupe.propertyID =tbl_booking.propertyID AND Dupe.bookingStartDate < tbl_Booking.bookingStartDate ORDER BY Dupe.bookingStartDate DESC) AS PriorBooking, (SELECT [tbl_guest].[guestMobile] FROM [tbl_guest] WHERE [tbl_booking].[guestID] = [tbl_guest].[guestID]) AS NewMobile, Right([NewMobile],4) AS NewKeySafe
FROM tbl_properties INNER JOIN (tbl_guest INNER JOIN tbl_booking ON tbl_guest.guestID = tbl_booking.guestID) ON tbl_properties.propertyID = tbl_booking.propertyID
WHERE (((tbl_properties.IsCleaned)=True) AND ((tbl_booking.bookingStatusCode)=3 Or (tbl_booking.bookingStatusCode)=5));
gets the booking number for the booking immediately preceding each booking. It seems that you cant use this subquery result to calculate another column so my second query
Code:
SELECT (SELECT [tbl_booking].[guestID] FROM [tbl_booking] WHERE [tbl_booking].[bookingID] = [qry_bookingsList1].[PriorBooking]) AS OldGuest, *
FROM qry_bookingsList1;
gets the guest Id for the previous booking. The third query
Code:
SELECT qry_bookingsList2.OldGuest, qry_bookingsList2.bookingID, (SELECT [tbl_guest].[guestMobile] FROM [tbl_guest] WHERE [tbl_guest].[guestID] = [qry_bookingsList2].[OldGuest]) AS OldMobile, *
FROM qry_bookingsList2;
then guests the previous guests mobile number form which can be extrapolated the previous key safe code. i.e. the last 4 digits.
When I run the 3rd query however my computer lags and access stops responding for about 20 seconds so i'm guessing that although I have achieved my result it has not been done in the right way? Have you any advice please?