473,503 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I Use DLookup() to Check a Logon

101 New Member
I am at a loss on how to write a DLookup to find the value of a field in a table based upon the value of a variable that relates to a different field in that table.

Scenario is:-
Tble 1 contains #ID (Long), Name (String) etc.
Tbl 2 has Name, Date etc but not an ID.

I have a form which has takes info for Tbl 2 and I have caputured the ID from the Login function.

I now want to compare the Name Chosen for Tbl 2 with the Login ID I have captured to see if the Name in both Tbl 1 & the Form for Tbl 2 Match.

I am getting really confused with the logic and wonder if you can advise me.

My Current Code is as follows:-
Expand|Select|Wrap|Line Numbers
  1.  If loginID = DLookup("strEmpName", "tblEmployees", "[lngEmpID] =" & Forms![frmBookings.BookName]) Then
  2.          'MsgBox ("Login Name Matches Login ID")
  3.          'Me!BookName.SetFocus
  4.          'Else
  5.          'MsgBox ("Not Matched")
  6.         'Exit Sub
  7.  
  8.         'End If
LoginID = the Login info captured...this will equal an Employee Record ID field

I Need to look in the tblEmployees and find the name associated with the ID which = LoginID.

Once I have this I can compare Names to see if they are equal.

I know my code is wrong but my brain has gone and I cannot figure out the logic.
Oct 22 '11 #1
6 2164
NeoPa
32,557 Recognized Expert Moderator MVP
How do you make something so simple into something so complicated? I can tell you've put effort into asking the question but wow!

First try this :
Expand|Select|Wrap|Line Numbers
  1. If loginID = DLookup("[lngEmpID]", _
  2.                      "[tblEmployees]", _
  3.                      "[strEmpName] = '" & Forms!frmBookings.BookName & "'") Then
If that works we don't need to go through the painful process of trying to make this question make sense.

Otherwise continue on and answer all these questions thoroughly and clearly if you would :
  1. What type of value would you expect to find in Forms!frmBookings.BookName? Is this a string value that matches both the fields in your two tables called [Name]?
  2. Forgetting [Tble 1] and [Tbl 2], which are introduced but never mentioned in your code or afterwards, which two tables are you dealing with (Clearly one is [tblEmployees], but the other one we don't know)?
  3. Is there any requirement in the question for the other table after all? My guess is that it's redundant as far as this question goes.
Oct 22 '11 #2
NeoPa
32,557 Recognized Expert Moderator MVP
By the way, if you already have an ID for the current user, and you also want to ensure none but the current user log on to this for entering information (In other words users can only enter data for themselves on this form), then would it not be simpler and more straightforward to use the ID already saved and simply populate the data on the form to reflect that value only. IE. No selection or entering required (that requires subsequent checking), but the value is provided from the information you already have available.

Would that not make more sense?
Oct 22 '11 #3
Cyd44
101 New Member
Sorry to confuse you but you clearly worked out what I meant as youur code worked. Many thanks agian my friend
Oct 22 '11 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I was able to guess (albeit correctly in this instance), but that's really not how things ought to work. I don't mean that unkindly. You clearly put in some effort as I recognised before. I wish there was something more helpful I could say, but it has to come from you really. It's always harder when you're deeply involved in something that has you confused, I appreciate.

What I will say for now, is just to suggest you give post #3 some careful consideration. It's easy to skip past other posts when you find what you're looking for, but you may miss another approach that makes the whole problem a lot simpler. See what you think anyway. I'll leave it with you.
Oct 22 '11 #5
Cyd44
101 New Member
Your points are taken NeoPa. You knowledge and advise is appreciated, as always. It may take me a little time but I do get there. It is my lack of syntax knowledge that is letting me down so I appreciate the help I can get here. post #3 comments considered as suggested.
Oct 24 '11 #6
NeoPa
32,557 Recognized Expert Moderator MVP
I was heartened to read your latest post. All good news it seems (Whatever decision you come to for now).
Cyd44:
It is my lack of syntax knowledge that is letting me down so I appreciate the help I can get here.
Whenever I struggle with syntax I find the Context-Sensitive Help invaluable. There is also good help for SQL syntax in the Help system too (See Finding Jet SQL Help).

And of course, we're always here to fill in any gaps.
Oct 24 '11 #7

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

Similar topics

3
2386
by: MUHAMAMD SALIM SHAHZAD | last post by:
dear respected Gurus, i would like to know what is wrong with my codes, i wanted to put PolicyNo(say any string value, which is PK in table)...how to do? as i make one inputbox it asked the...
2
5044
by: bobabooey2k | last post by:
I have an update query with one field having in its "Update to" cell a DLookup statement. This query takes 2-3 minutes on 3000 records. Can I avoid dlookup here using multiple queries? An...
8
4554
by: MLH | last post by:
The following SQL returns PRECISELY what I want: SELECT TOP 1 tblCorrespondence.CorrespID, tblOutboundTypes.OTypDescription, tblCorrespondence.OutDate, tblCorrespondence.VehicleJobID,...
3
4504
MSeda
by: MSeda | last post by:
I have a loop that is controlled by a Dlookup statement with two criteria. Both criteria fields are checkboxes. I have tried an assortment of quotation marks in the criteria section and cannot get...
5
8601
by: td0g03 | last post by:
Here is the question....Write a statement that declares a prototype for a function divide that takes four arguments and returns no value. The first two arguments are of type int . The last two...
2
1597
by: hr833 | last post by:
i'm having trouble with Dlookup.I'm trying to insert a Dlookup statement in a update query, so that the user need not upate each record manually. Supplier Catergory sSupplierName sCatergory ...
19
2329
by: pitamber kumar | last post by:
Write a program to find the number of and sum of all intergers greater than 100 & less than 200 that are divisible by 7.
3
11239
by: adigga1 | last post by:
Hello Experts, I'm about to go grey with this dlookup statement: I'm trying to run a dlookup statement, I have the correct expression string, etc. but when I run it under the Immediate window...
3
5582
by: sivadhanekula | last post by:
Hi...every one... I have a problem with below statement here the underlined fullname is the item from combo box If I have the same statement without LIMIT then the program is...
0
7201
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
7083
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...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.