Below is my code... But it does not seems to work :-(
1. If my booking ID is blank It displays the error message and enters the next field. Goes through the validation of the next field pops up the message. displays the ID error message and sets the cursor to the last field my form.
2. I have added in the validation rule = Is Not Null and Validation text = ooking ID cannot be blank
3. Changed the code from txtbookingid.Setfocus to SendKeys "+{TAB}"
4. Similar code for other field validation works fine, but for this one I am stuck.
Not sure where I am going wrong.
Private Sub txtbookingid_LostFocus()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyVal As Long
Dim strSql As String
Set db = CurrentDb()
If Me.txtbookingid = "" Or IsNull(Me.txtbookingid) Then
MsgBox ("Booking ID cannot be blank")
SendKeys "+{TAB}"
Else
strSql = "SELECT BookingID,StartDate,EndDate,NoAdults,NoChildren " & _
"FROM Booking_Header " & _
"WHERE BookingID = " & Me.txtbookingid & "" & _
"AND BookingStatus NOT IN ('COMPLETED','CANCELLED')"
Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
If rs.RecordCount = 0 Then
MsgBox (" Please enter the customer details before planing the Itinerary")
Me.txtbookingid = ""
SendKeys "+{TAB}"
Else
Me.txtstartdate = (rs!Startdate)
Me.txtenddate = (rs!Enddate)
Me.txtNA = (rs!NoAdults)
Me.txtNC = (rs!NoChildren)
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub