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.
Solved: -
Private Sub btnLoginOK_Click()
-
-
Dim FirstName As String
-
-
If IsNull(Me.txtLoginID) Then
-
MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
-
Me.txtLoginID.SetFocus
-
Else
-
'process the job
-
FirstName = Nz(DLookup("[FName]", "UserLogin", "[ProcessorID]= '" & Me.txtLoginID & "'"))
-
If FirstName = "" Then
-
MsgBox "Sorry, Don't recognise you"
-
Exit Sub
-
End If
-
-
MsgBox "Welcome " & FirstName
-
DoCmd.OpenForm "Questionnaire"
-
DoCmd.Close acForm, "LoginForm"
-
End If
-
-
End Sub
-
Phil
16 931
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 -
Dlookup("FName", "UserLogin","[ProcessorID]= " & CLng(me.txtLoginID))
-
Also. for clarity, make sure there are spaces on both sides of the "&"
Phil
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 - Private Sub btnLoginOK_Click()
-
If IsNull(Me.txtLoginID) Then
-
MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
-
Me.txtLoginID.SetFocus
-
Else
-
'process the job
-
Dlookup("[Fname]", "LoginForm", "ProcessorID = '"& txtLoginID.Value &"'")
-
MsgBox "Welcome"
-
DoCmd.OpenForm "Questionnaire"
-
DoCmd.Close acForm, "LoginForm"
-
End If
-
End Sub
If that helps any.
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" -
Dlookup("FName", "UserLogin", "[ProcessorID]= '" & me.txtLoginID & "'")
-
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
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: - Dlookup("[FName]", "UserLogin", "[ProcessorID]= '" & me.txtLoginID & "'")
-
MsgBox "Welcome"
-
DoCmd.OpenForm "Questionnaire"
-
DoCmd.Close acForm, "LoginForm"
-
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.
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
How would I go about posting my table? I am sorry I am a newbie here.
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
Here is my table. Let me know if there is anything else you need.
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 -
Debug.Print me.txtLoginID
-
Phil
When I debug it says syntax error.
Would it have to do anything with my textbox being unbound?
Sorry, try changing the dot to an exclamation mark ! -
Debug.Print me!txtLoginID
-
Phil
Here is my file. Let me know what you find.
Solved: -
Private Sub btnLoginOK_Click()
-
-
Dim FirstName As String
-
-
If IsNull(Me.txtLoginID) Then
-
MsgBox "Please Enter Employee ID", vbInformation, "LoginID Required"
-
Me.txtLoginID.SetFocus
-
Else
-
'process the job
-
FirstName = Nz(DLookup("[FName]", "UserLogin", "[ProcessorID]= '" & Me.txtLoginID & "'"))
-
If FirstName = "" Then
-
MsgBox "Sorry, Don't recognise you"
-
Exit Sub
-
End If
-
-
MsgBox "Welcome " & FirstName
-
DoCmd.OpenForm "Questionnaire"
-
DoCmd.Close acForm, "LoginForm"
-
End If
-
-
End Sub
-
Phil
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?
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
Okay got it! Thank you so much Phil.
Sign in to post your reply or Sign up for a free account.
Similar topics
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"...
|
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...
|
by: khan |
last post by:
getting, error, 3075
Syntax Error (Missing Operator) in query expression '8WHERE
.=1'
Dim TotalQty As Integer
TotalQty = DLookup("", "", "=" &
Forms!!)
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |