If Statement is Wacky

D

DS

This IIf statement is not working...it doesn't do anything.
I tried changing the first part of if to

If Me.TxtDisplay <> Me.TxtDupeID Then

then I did get the "DUPLICATE ID"
but the second part still wouldn't work.
Any help appreciated.
Thanks
DS


Select Case
Case 14
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = " &
Me.TxtDisplay & ""), 0)
If Me.TxtDisplay = Me.TxtDupeID Then
DoCmd.OpenForm "FXMsgWarning"
Forms!FXMsgWarning!TxtMsg = "DUPLICATE ID"
ElseIf Me.TxtDupeID = 0 Then
DoCmd.Close acForm, "PadNumber"
End If
End Select
 
G

Graham R Seach

The original code looks pretty much OK to me, except that (assuming
EmployeeID is numeric) the DLookup statement should be as follows:
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = " &
Me.TxtDisplay), 0)

If EmployeeID is meant to be textual, then the statement should be as
follows:
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = """
& Me.TxtDisplay & """"), 0)

If it's not working, then I suggest you use F8 to step through the code and
use the Immediate Window to check the value of each statement as each step
executes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
D

DS

Graham said:
The original code looks pretty much OK to me, except that (assuming
EmployeeID is numeric) the DLookup statement should be as follows:
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = " &
Me.TxtDisplay), 0)

If EmployeeID is meant to be textual, then the statement should be as
follows:
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = """
& Me.TxtDisplay & """"), 0)

If it's not working, then I suggest you use F8 to step through the code and
use the Immediate Window to check the value of each statement as each step
executes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

This IIf statement is not working...it doesn't do anything.
I tried changing the first part of if to

If Me.TxtDisplay <> Me.TxtDupeID Then

then I did get the "DUPLICATE ID"
but the second part still wouldn't work.
Any help appreciated.
Thanks
DS


Select Case
Case 14
Me.TxtDupeID = Nz(DLookup("[EmployeeID]", "Employees", "EmployeeID = " &
Me.TxtDisplay & ""), 0)
If Me.TxtDisplay = Me.TxtDupeID Then
DoCmd.OpenForm "FXMsgWarning"
Forms!FXMsgWarning!TxtMsg = "DUPLICATE ID"
ElseIf Me.TxtDupeID = 0 Then
DoCmd.Close acForm, "PadNumber"
End If
End Select
Thanks Graham...It was the Quotes.
DS
 

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

Similar Threads

Complex If Statement 6
If Statement 4
Nested If 3
greater than and less than in If statement 4
VBA works in orignal but fails in copy of database 1
Correct use of IF ElseIf 5
Code Is Slow 3
If Statement 7

Top