Duplicate in last 100 records

A

aMack

I need a Msgbox to appear as a warning only if a data field matches within
the last 100 records:

Each record is an order with Key field [REF#]

If the data field [Container] matches within the last 100 [REF#]'s than I
need a MsgBox to appear "Are You Sure - this Container exists on REF XXXXXX"

I think I would add the code builder to the ON Exit event but do not know
how to compare the current record to a the last 100 records and I do not know
how to pull the [REF#] and put it in the msgbox.

Is there a different way to do this?

Thanks
 
M

Marshall Barton

aMack said:
I need a Msgbox to appear as a warning only if a data field matches within
the last 100 records:

Each record is an order with Key field [REF#]

If the data field [Container] matches within the last 100 [REF#]'s than I
need a MsgBox to appear "Are You Sure - this Container exists on REF XXXXXX"

I think I would add the code builder to the ON Exit event but do not know
how to compare the current record to a the last 100 records and I do not know
how to pull the [REF#] and put it in the msgbox.


Try creating a query to retrieve the highest 100 Ref
numbers:

SELECT TOP 100 [Ref#[ FROM table ORDER BY [Ref#] DESC

Then you can use code something like this in the Ref# text
box's BeforeUpdate event:

If DCount("*", "query", "[Ref#]=" & Me.textbox) > 0 Then
If MsgBox("are you sure ...", vbYesNo) = vbNo Then
Camcel = True
Me.textbox.Undo
End If
End If
 
A

aMack

code entered as follows: (Query name is "Selectlast100"

If DCount("*", "Selectlast100", "[Container]= " & Me.Container) > 0 Then
If MsgBox("Are you sure this Container is correct", vbYesNo) = vbNo Then
Cancel = True
Me.Container.Undo
End If
End If

I get an error: "Run Time Error "2001"

It takes me to the If DCount line and highlights it???

This is still not all I need - the MsgBox needs to container the [REF#]
where the duplicate exists.

Thanks

--
A MACKENZIE, CMA, MBA


Marshall Barton said:
aMack said:
I need a Msgbox to appear as a warning only if a data field matches within
the last 100 records:

Each record is an order with Key field [REF#]

If the data field [Container] matches within the last 100 [REF#]'s than I
need a MsgBox to appear "Are You Sure - this Container exists on REF XXXXXX"

I think I would add the code builder to the ON Exit event but do not know
how to compare the current record to a the last 100 records and I do not know
how to pull the [REF#] and put it in the msgbox.


Try creating a query to retrieve the highest 100 Ref
numbers:

SELECT TOP 100 [Ref#[ FROM table ORDER BY [Ref#] DESC

Then you can use code something like this in the Ref# text
box's BeforeUpdate event:

If DCount("*", "query", "[Ref#]=" & Me.textbox) > 0 Then
If MsgBox("are you sure ...", vbYesNo) = vbNo Then
Camcel = True
Me.textbox.Undo
End If
End If
 
M

Marshall Barton

aMack said:
code entered as follows: (Query name is "Selectlast100"

If DCount("*", "Selectlast100", "[Container]= " & Me.Container) > 0 Then
If MsgBox("Are you sure this Container is correct", vbYesNo) = vbNo Then
Cancel = True
Me.Container.Undo
End If
End If

I get an error: "Run Time Error "2001"

It takes me to the If DCount line and highlights it???

This is still not all I need - the MsgBox needs to container the [REF#]
where the duplicate exists.


If MsgBox("Are you sure Container " & Me.[Ref#] & " is
correct", vbYesNo) = vbNo Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top