dlookup problem

basilyos

Registered User.
Local time
Today, 12:20
Joined
Jan 13, 2014
Messages
256
hello guys i want to check if the number and the date of telegram is existed

the number should be LIKE not equal
the date should be equal

this is what i wrote

Code:
If DLookup("Telegram_Number", "tbl_Violation_Of_Building", "Telegram_Number Like " + Forms!frm_Add_Violation_Building!Telegram_Number + " And Telegram_Date =  #" & Format(Forms!frm_Add_Violation_Building!Telegram_Date, "yyyy/mm/dd") & "#") Then
MsgBox ("number existed")
Me.Telegram_Date = Null
Me.Telegram_Number = Null
Me.Telegram_Number.SetFocus
End If

this code is working if the number and date is equal for example
if number = 12 and date = 01/01/2015
and i enter number = 12 and date = 01/01/2015
so i got a msg "number existed
but if number = 12 - 50 and date = 01/01/2015
and i enter number = 12 and date = 01/01/2015
i got nothing

any help??
 
i add the "*"

If DLookup("Telegram_Number", "tbl_Violation_Of_Building", "Telegram_Number Like ""*" & Forms!frm_Add_Violation_Building!Telegram_Number & "*"" And Telegram_Date = #" & Format(Forms!frm_Add_Violation_Building!Telegram_Date, "yyyy/mm/dd") & "#") Then


but now i'm getting Run-time error '13': Type mismatch
 
Is Telegram_Number field a text or number, what you've made is for text field.
 
Then remove the ".
Code:
If DLookup("Telegram_Number", "tbl_Violation_Of_Building",  "Telegram_Number Like "[B][COLOR=Red]"[/COLOR][/B]*" &  Forms!frm_Add_Violation_Building!Telegram_Number & "*[B][COLOR=Red]"[/COLOR][/B]" And  Telegram_Date =  #" &  Format(Forms!frm_Add_Violation_Building!Telegram_D  ate, "yyyy/mm/dd")  & "#") Then
 
thank you JHB for your help

Code:
If DLookup("Telegram_Number", "tbl_Violation_Of_Building", "Telegram_Number Like " * " & Forms!frm_Add_Violation_Building!Telegram_Number & " * " And  Telegram_Date =  #" & Format(Forms!frm_Add_Violation_Building!Telegram_Date, "yyyy/mm/dd") & "#") Then


i did it but i'm getting an error

run-time error 13

type mismatch


but when i removed the wild card the vba change this "*" to this " * "
maybe this is the problem ???
 
Could you post your database with some sample data, zip it?
 
thanks for your hard work

please try in the telegram number 41288
and in the telegram date 2014/10/10

sorry but it's in arabic language
 

Attachments

Yes ofcause, you can't use DLookup" in combination with a If, you need to use Dcount.
Code:
If DCount("Telegram_Number", "tbl_Violation_Of_Building", "[Telegram_Number] Like '*" & Me.Telegram_Number & "*' And Telegram_Date = #" & Format(Me.Telegram_Date, "yyyy/mm/dd") & "#") Then
 

Users who are viewing this thread

Back
Top Bottom