473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

dlookup and like error

Hi,
firstly, here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub paragelia_BeforeUpdate(Cancel As Integer)
  2. Dim varTemp As Variant
  3. Dim varTemp1 As Variant
  4. Dim sFilter As String
  5. Dim inputtext As Long
  6. Dim astrWhere As String
  7.  
  8.  
  9. inputtext = InStr(1, Forms![frm_kataxorisi]![paragelia], "-")
  10.  
  11. sFilter = Left(Forms![frm_kataxorisi]![paragelia], inputtext - 1)
  12. varTemp = DLookup("[ypiresia]", "tbl_kataxorisi", "[ypiresia] = Forms![frm_kataxorisi]![ypiresia]")
  13.  
  14. varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like 'sFilter'")
  15.  
  16.  
  17. If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1 = Forms![frm_kataxorisi]![paragelia] Then
  18. Me.Undo
  19. MsgBox "Η Τιμή αυτή έχει ήδη καταχωρηθεί", vbOKOnly, "Προσοχή Διπλότυπη καταχώρηση"
  20. Else
  21. MsgBox ("hi")
  22. End If
  23.  
  24. End Sub
I manage to take the value before (-) with sFilter(string), but i cannot put this in dlookup function to find only values, which will consist of sFilter value.
Thanks in advance!
Jun 10 '12 #1

✓ answered by nico5038

For a LIKE you need to use a "*" or "%" as wildcharacter.
So for a match with "1052-a" you would need as LIKE string "1052%" so the code would look like:
Expand|Select|Wrap|Line Numbers
  1. varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like '"& sFilter & "%'")
Nic;o)

9 2752
nico5038
3,080 Expert 2GB
Change:
Expand|Select|Wrap|Line Numbers
  1. varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like 'sFilter'")
into

Expand|Select|Wrap|Line Numbers
  1. varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like '"& sFilter & "'")
Nic;o)
Jun 10 '12 #2
thanks for your answer.
Now, i dont face any problem but i cannot have that i want because if i put in field Forms![frm_kataxorisi]![paragelia] the value 1052-a, the string sFilter take the value =1052, but after that no value in vartemp1=null, and i dont why is happening.
If i dont use like function and just take the whole field everything is ok.
Jun 10 '12 #3
nico5038
3,080 Expert 2GB
For a LIKE you need to use a "*" or "%" as wildcharacter.
So for a match with "1052-a" you would need as LIKE string "1052%" so the code would look like:
Expand|Select|Wrap|Line Numbers
  1. varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like '"& sFilter & "%'")
Nic;o)
Jun 10 '12 #4
thanks again.
I try this, but nothing happening.
Lets say that when i write (1052/12-a or 1234-5 or 1052-f), i take as sFilter= 1052/12 or 1234 or 1052 and i want to search my table.[paragelia], so as to see if there is a value which will consist of these values.
In my table i have values 1052/12-a-b, 1052-b, 1234.
Jun 10 '12 #5
nico5038
3,080 Expert 2GB
Can you place a breakpoint in the code (click in left ruler) and execute the code till the DLOOKUP.
Next type in the immediate window at the bottom:
Expand|Select|Wrap|Line Numbers
  1. ?"[paragelia] like '"& sFilter & "%'"
and report here the result.

Nic;o)
Jun 10 '12 #6
here is my report
[paragelia] like '1052%'
Jun 10 '12 #7
I understand my fault nico5038, after your propositions.
I had to change my .....If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1 = Forms![frm_kataxorisi]![paragelia] Then...... with..... If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1>0 Then....., so as my code says that there is a record which catch these criterias.
Thanks very match for your replies.
P.S. Do you know any way to have management system about my ms access db, i want to create manually login users with permissions and i id like to have a log files.
Jun 10 '12 #8
nico5038
3,080 Expert 2GB
I personally use regularly the windows userid of the person logged in. You can get that using the environ() function like:
Expand|Select|Wrap|Line Numbers
  1. strUsername = environ("username")
Thus I'm sure only people allowed to use the system will be able to run my access application. Placing the allowed users within the company in an authorization table will limit the access to the intended users and you can log the users starting the application.

Nic;o)
Jun 10 '12 #9
thanks again.
Have a nice day!
Jun 11 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
2
by: Maziar Aflatoun | last post by:
Hi everyone, I setup windows authentication on my webapplication. It's been working fine for the past two years. But all of a sudden it gives me the following error when I login using one of...
1
by: MUHAMAMD SALIM SHAHZAD | last post by:
dear sir, i would like to get your assitance about the above issues, can't find any better slutions or codes - table name: MOTOR2000 - field name1: POLICYNO - field name2: ExPolicyNo i...
2
by: Steve Richfield | last post by:
My error handler works GREAT. However, VBA seems to have some bugs/features that are causing it fits. The little snippet that I put at the end of each routine looks like this: Error_Handler: If...
8
by: Uros | last post by:
Hello! I have problem with my function and I can find what's wrong. WARNING: Error occurred while executing PL/pgSQL function fn_insert_entry_pending WARNING: line 26 at SQL statement...
13
by: nzyui | last post by:
Trying to lookup a field from a table called condition this is a separate table not linked to anything: setup as shown Code S M L DG 1 2 3 RI 2 4 5 need...
3
by: access345 | last post by:
I have created a form to lookup components in a table. The problem I am having is the table I have has multiple designations in the same field. Ex CR2,CR4,CR18 If I am looking up a field that has...
1
by: bagya | last post by:
please help me out the following is the small code i have <html> <head> <script type="text/javascript"> function validate() { if (document.abc.region.value==0)
15
by: niteshkpatil | last post by:
Hi, I am compiling a C program on Hp-UX11.11 using the HP C compiler. % cc test.c (say for example....) I get the following message and the compilation is aborted. % cc: panic 3011:
8
by: Paul Furman | last post by:
How do I turn off MySQL error reporting? I set error_reporting(0); but that doesn't seem to be working.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.