Notice a few cosmetic changes to code. There was only one line that could
really be a problem, there is a ' missing in this line:
Me.Recordset.FindFirst "ADDRESS=" & varADDRESS
The Step Into will not trace the code line by line. Open your form in
Design View then Open your VBA editor, get into the sub you want to trace,
put your cursor on the first line of executable code and press F9. You will
it highlight. No go back to your form, do whatever it takes to get the code
to execute. The VBA editor will pop up and you will see a line highlighted
in yellow. That is the line that will execute next. Then, press F8, the
line will execute and the next line will highlight.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim varADDRESS As Variant
If Me.NewRecord Then
(change) varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", "[ADDRESS]
= '" &
Me.ADDRESS _
(change) & "' and [STREET] = '" & Me.LOCATION & "' and [STREET1]
= '" &
Me.STREET1 _
& "'")
If Not IsNull(varADDRESS) Then
If MsgBox("This record already exists." & _
"Do you want to cancel these changes and go to that
record instead?", _
vbQuestion + vbYesNo, _
"Duplicate Address Found") _
= vbYes _
Then
Cancel = True
Me.Undo
(change) Me.Recordset.FindFirst "[ADDRESS] ='" & varADDRESS
& "'"
End If
End If
End If
End Sub
Trini Gal said:
When I click the compile, no errors show up and when I click the Step Into,
nothing happens, I hear a "ding" and thats all. Is the code even right?
I'm sorry for being such a headache.
:
Have you run it in debug mode and stepped through it to see what it is doing?
:
Hello,
Can someone please help me with this code. When I debug it, no errors show
up. When I test it in the form, nothing happens, the duplicate data is just
saved. I'm sorry to keep bugging about this. I'm fairly new to VB Coding.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim varADDRESS As Variant
If Me.NewRecord Then
varADDRESS = DLookup("ADDRESS", "LEAKS FOUND", "ADDRESS = '" &
Me.ADDRESS _
& "' and STREET = '" & Me.LOCATION & "' and STREET1 = '" &
Me.STREET1 _
& "'")
If Not IsNull(varADDRESS) Then
If MsgBox("This record already exists." & _
"Do you want to cancel these changes and go to that
record instead?", _
vbQuestion + vbYesNo, _
"Duplicate Address Found") _
= vbYes _
Then
Cancel = True
Me.Undo
Me.Recordset.FindFirst "ADDRESS=" & varADDRESS & "'"
End If
End If
End If
End Sub
Thanks.
Hello,
I have a problem that I can't seem to find the solution to.
I have a table with three fields (Address, Street, Street1), that when put
together maked up a street address.
eg. Address - 100, Street - East Main, Street1 - Street, when added
together
for a report becomes 100 East Main Street
My issue is that when the user enters new information into my forms, I
want
ACCESS to check to see if when Address, Street, and Street1 is added
together
equal data that already exists. And if the data already exist have a pop
up
notification box that notifies the users that the data already exists, and
populate all the fields with the existing data.
Is this possible???
Thanks in advance for your time.