|
|
Question : Access-Coding NZ(Dlookup)
|
|
Hello,
Have code below in DateofTravel_BeforeUpdate event.
Private Sub DateofTravel_BeforeUpdate(Cancel As Integer) Dim LResponse As Integer Dim fromlocationget As Integer Dim tolocationget As Integer
Dim realfrom As String Dim realto As String
If Nz(DLookup("PersonID", "CompareDataofday", "PersonID=" & Me.Parent.PersonID & " AND DateOfTravel=#" & Me.DateofTravel & "#"), "") <> "" Then fromlocationget = Nz(DLookup("[FromLocation]", "CompareDataofday", "PersonID=" & Me.Parent.PersonID & " AND DateOfTravel=#" & Me.DateofTravel & "#"), "") tolocationget = Nz(DLookup("ToLocation", "CompareDataofday", "PersonID=" & Me.Parent.PersonID & " AND DateOfTravel=#" & Me.DateofTravel & "#"), "") realfrom = Nz(DLookup("Location", "Locationqry", "LocationID=" & fromlocationget), "") realto = Nz(DLookup("Location", "Locationqry", "LocationID=" & tolocationget), "")
LResponse = MsgBox("This person " & Me.Parent.Last & " already has the same Travel Date from " & realfrom & " TO " & realto & ".Do you still wish to add this flight?", vbYesNo, "Duplicated Data Found") If LResponse = vbYes Then Else DoCmd.RunMacro "Closeperson" DoCmd.RunMacro "Openperson" Exit Sub End If End If
It tells the user that information about this person has been entered and displays the from location then to location in a message box -then ask the user if they would like to continue. What I realized is its not in the correct event or field event. I need to move it to the unbound FromLocationID and unbound ToLocation combo boxes and add more code to the: If Nz(DLookup("PersonID", "CompareDataofday", "PersonID=" & Me.Parent.PersonID & " AND DateOfTravel=#" & Me.DateofTravel & "#"), "") <> "" Then
It needs to check if all above match and the From location and To location match from CompareDateofday"
Thanks for your help
Im attaching database if needed -Form Person_TBL
|
Answer : Access-Coding NZ(Dlookup)
|
|
I'm not sure I understand ... if you need to move the code to your unbound combos, then just move the entire codeblock to the AfterUpdate event of those combos ... if you need to refer to the Combos in the DLookup, then just change the DLookups to reflect that.
|
|
|
|
|