473,385 Members | 1,769 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,385 software developers and data experts.

Dlookup give san error saying I am missing an operator

I am trying to make a login form and used dlookup to confirm that the first name belongs to the employee ID entered.

Dlookup("FName", "UserLogin","[ProcessorID]= '"&me.txtLoginID.value &"'")

I keep getting an error saying I am missing =. Help please.
Mar 2 '17 #1

✓ answered by PhilOfWalton

Solved:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnLoginOK_Click()
  2.  
  3.     Dim FirstName As String
  4.  
  5. If IsNull(Me.txtLoginID) Then
  6.     MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
  7.     Me.txtLoginID.SetFocus
  8. Else
  9.     'process the job
  10.     FirstName = Nz(DLookup("[FName]", "UserLogin", "[ProcessorID]= '" & Me.txtLoginID & "'"))
  11.     If FirstName = "" Then
  12.         MsgBox "Sorry, Don't recognise you"
  13.         Exit Sub
  14.     End If
  15.  
  16.     MsgBox "Welcome " & FirstName
  17.     DoCmd.OpenForm "Questionnaire"
  18.     DoCmd.Close acForm, "LoginForm"
  19.     End If
  20.  
  21. End Sub
  22.  
Phil

16 931
PhilOfWalton
1,430 Expert 1GB
What sort of field is ProcessorID? I suspect it is numeric.
What is a typical value of Me.TxtLogin? Is it also numeric, if not you might try

Expand|Select|Wrap|Line Numbers
  1. Dlookup("FName", "UserLogin","[ProcessorID]= " & CLng(me.txtLoginID))
  2.  
Also. for clarity, make sure there are spaces on both sides of the "&"

Phil
Mar 2 '17 #2
ProcessorID is a text field as well as txtLogin.
I did try that code and it did not work.

Dlookup("[Fname]", "LoginForm", "[ProcessorID]=" & CLng(Me.txtLoginID.Value))

Me entire code is

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnLoginOK_Click()
  2. If IsNull(Me.txtLoginID) Then
  3.     MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
  4.     Me.txtLoginID.SetFocus
  5. Else
  6.     'process the job
  7.     Dlookup("[Fname]", "LoginForm", "ProcessorID = '"& txtLoginID.Value &"'")
  8.     MsgBox "Welcome"
  9.     DoCmd.OpenForm "Questionnaire"
  10.     DoCmd.Close acForm, "LoginForm"
  11.     End If
  12. End Sub

If that helps any.
Mar 2 '17 #3
PhilOfWalton
1,430 Expert 1GB
OK. Your last code will not work because a DLookup works only on tables and queries, not on a form

So try your original code again but with spaces round the "&" but without the word ".Value"

Expand|Select|Wrap|Line Numbers
  1. Dlookup("FName", "UserLogin", "[ProcessorID]= '" & me.txtLoginID & "'")
  2.  
Also can you confirm that both FName & ProcessorID are in your UserLogin table?

Also I would be rather inclined to run the code on the AfterUpdate of the TxtLoginID rather than on a separate command button.

Unfortunately the code that you have written after the Else clause doesn't really do anything.
It looks up someone's first name and doesn't do anything with it. E.G. compare it to the first name of the person who is logging on, just opens a message box to say "Welcome" which the operator hat to waste their time clicking the OK button, and then does what is wanted by opening the Questionnaire form.

Phil
Mar 2 '17 #4
Thank you so much for your help Phil. Unfortunately, it is still giving me the same error. I can confirm that both ProcessorID and FName are in my UserLogin table. My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Dlookup("[FName]", "UserLogin", "[ProcessorID]= '" & me.txtLoginID & "'")
  2.     MsgBox "Welcome"
  3.     DoCmd.OpenForm "Questionnaire"
  4.     DoCmd.Close acForm, "LoginForm"
  5.     End If 
My intentions for the clause after else is for a pop up to say "Welcome (FName) (LName)." I was thinking that by looking up the values I would be able to input them into the message.
Mar 3 '17 #5
PhilOfWalton
1,430 Expert 1GB
Not that I doubt you, but there is something very odd here.

Please can you post your UserLogin table.

If you put a debug stop on the DLookup Line, what value are you getting for the me.txtLoginID.

I am a little suspicious (don't know why) but I would expect the word me. would be capitalised to Me. In all my databases, the editor always capitalises the word Me. It's as if it isn't being recognised.

Phil
Mar 3 '17 #6
How would I go about posting my table? I am sorry I am a newbie here.
Mar 3 '17 #7
PhilOfWalton
1,430 Expert 1GB
Well you could either do a PrintScreen of tour table in design view and send the image, or better still if you remove any sensitive information from your database, you can send it as a zip file.

That can either be posted on the Bytes website, or if you send me a personal message, we can arrange that you send the zip file directly to me

Phil
Mar 3 '17 #8
Here is my table. Let me know if there is anything else you need.
Attached Images
File Type: png UserLogin.PNG (9.2 KB, 96 views)
Mar 3 '17 #9
PhilOfWalton
1,430 Expert 1GB
Table looks fine.

So if you debug the code, what value are getting (see my earlier post) for me.txtLoginID

Another way of getting this is on the first line of code type

Expand|Select|Wrap|Line Numbers
  1. Debug.Print me.txtLoginID
  2.  
Phil
Mar 3 '17 #10
When I debug it says syntax error.

Would it have to do anything with my textbox being unbound?
Mar 3 '17 #11
PhilOfWalton
1,430 Expert 1GB
Sorry, try changing the dot to an exclamation mark !

Expand|Select|Wrap|Line Numbers
  1. Debug.Print me!txtLoginID
  2.  
Phil
Mar 3 '17 #12
Here is my file. Let me know what you find.
Attached Files
File Type: zip MPPDB Master - Copy.zip (449.5 KB, 50 views)
Mar 3 '17 #13
PhilOfWalton
1,430 Expert 1GB
Solved:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnLoginOK_Click()
  2.  
  3.     Dim FirstName As String
  4.  
  5. If IsNull(Me.txtLoginID) Then
  6.     MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
  7.     Me.txtLoginID.SetFocus
  8. Else
  9.     'process the job
  10.     FirstName = Nz(DLookup("[FName]", "UserLogin", "[ProcessorID]= '" & Me.txtLoginID & "'"))
  11.     If FirstName = "" Then
  12.         MsgBox "Sorry, Don't recognise you"
  13.         Exit Sub
  14.     End If
  15.  
  16.     MsgBox "Welcome " & FirstName
  17.     DoCmd.OpenForm "Questionnaire"
  18.     DoCmd.Close acForm, "LoginForm"
  19.     End If
  20.  
  21. End Sub
  22.  
Phil
Mar 3 '17 #14
Thank you so much!!!! This is exactly what I wanted! Is there a way to go back to the login form if the user says that is not them?
Mar 3 '17 #15
PhilOfWalton
1,430 Expert 1GB
The normal way to use a login form is to ask for 2 bits of information so something like they enter the first name, then enter the number which looks up the first name. If they match go on, if not, clear both fields and try again.

Phil
Mar 3 '17 #16
Okay got it! Thank you so much Phil.
Mar 3 '17 #17

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

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
1
by: JMCN | last post by:
I have an ftp program that i inherited and i tried to modify it to ftp over my file however, i receive an error message : run-time error '3075 syntax error (missing operator) in query expression...
4
by: khan | last post by:
getting, error, 3075 Syntax Error (Missing Operator) in query expression '8WHERE .=1' Dim TotalQty As Integer TotalQty = DLookup("", "", "=" & Forms!!)
3
by: william | last post by:
Hello Everyone, I'm using Access 2000. I entered the following code to do some data validation, however it is not working. I'm trying to ensure that the user cannot enter a duplicate inspection...
2
by: sfrvn | last post by:
I am embarrassed to say I cannot make this work. Recently upgraded to Access 2003, but do not know if that part of problem (AKA 'syntax change'). Would someone be kind enough to lead me by the...
2
by: msaurea | last post by:
Hi, I have getting the error about this. Hope you could help SELECT .UPC_ID, DB2SH000_LU_NUTRIENT_FACTOR.UPC_ID, DB2SH000_LU_NUTRIENT_FACTOR.NDB_NBR, .Source FROM LEFT JOIN...
7
by: Cyd44 | last post by:
Hope someone can help with a query expression. I am trying to open a form from a variable set in another form and have the following query set on button click:- If Not Me.NewRecord Then...
3
by: Bennett72 | last post by:
Hello - I'm getting a run time error 3075 (missing operator) in my query expression and cannot seem to determine why. I cut a snippet of code (see below) and ran the statement in a sql query view...
5
by: dago87 | last post by:
Hello. I have following function in my query DLookUp("name","Qshortages","Qshortages.ItemNumber='" & & "'") AS Facility I'm getting an error: Syntax error (missing operator) in query expression:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.