Dlookup not working

I have an impending disaster guys!  I have a purchase order system that if an order is over a certain value a manager is required to enter an authorisation number.  The manager obtains this from a table and ticks a box to a) issue it, and b) so that it cannot be re-used.

The authorisation field on the form takes this number, looks up the check table (called pincheck) and if it exists, and has not been used up, it inserts it and allows the user to move through the form.

This is the code on the after_update event of the authorisation number field (which is only made visible if the order value is >50):

Dim sPin As String

sPin = Nz(DLookup("pin", "pincheck", "not deleted"))

If sPin = Me.Text62 Then
    MsgBox "Valid PIN entered - please proceed with order", vbInformation, "RF Materials Ordering"
    Me.Order_number.Visible = True
Else
    MsgBox "Invalid PIN entered - please check and try again", vbCritical, "RF Materials Ordering"
   
End If

It's behaviour is erratic - now it seems to have stopped working.  Any help REALLY needed guys!

Thanks
Lapchien


LapchienDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LapchienDirectorAuthor Commented:
NB - the pincheck table contains 4 columns - auto (PK), pin, usedup and deleted.

0
shanesuebsahakarnCommented:
Try:

If Not IsNull(DLookUp("[pin]","pincheck","[pin]='" & Me!Text62 & "'")) Then
   'Valid PIN entered
Else
   'Invalid PIN entered
End If
0
shanesuebsahakarnCommented:
Note - this:

sPin = Nz(DLookup("pin", "pincheck", "not deleted"))

returns the *first* PIN in the table where the deleted field is False, regardless of what that pin might be. My code should be modified to take this into account:

If Not IsNull(DLookUp("[pin]","pincheck","[pin]='" & Me!Text62 & "' AND [Deleted]=False")) Then
   'Valid PIN entered
Else
   'Invalid PIN entered
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LapchienDirectorAuthor Commented:
Thanks Sahne - when the manager issues the auth nbr he also checks 'deleted' to stop it from being issued again and to stop it from being a valid number...

0
shanesuebsahakarnCommented:
The above should do it.
0
will_scarlet7Commented:
Hi Lapchien,
What about using the following instead:

sPin = Nz(DLookup("pin", "pincheck", "pin =" & Me!Text62 ))
0
will_scarlet7Commented:
I sure was the turttle that time...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.