473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using DLookup function to reference a table

45 New Member
I have a table called users and a field in that table called amountauthorized.

My users enter a figure in a text box called estp on a form. estp is either equal to or less than the amountauthorized.

I want the code to check the figure in estp and compare it to amountauthorized in the table and if the figure in estp is greater than amountauthorized display message "Figure over authorized limit".

The following is the code I have written but I keep getting expression expected error .

I am new to vba and would appreciate your help and guidance with this

Expand|Select|Wrap|Line Numbers
  1. Dim x As String
  2. x => (estp)
  3. x = DLookup("amountauthorized", "Users", "UserName = test")
  4. If (estp) < 200 And text33 = "test" Then
  5. MsgBox "Amount Over approval limit"
  6. End Sub 
  7.  
NOTE:
text33 is another user field in the form and is the same as UserName field in the table.

Thank you
Jan 24 '10 #1

✓ answered by nico5038

OK, guess we have a datatype problem.
1) Check that amountauthorized is a numeric field
2) Make the estp field also numeric or change "Me.estp" into "Val(Me.estp)"

Nic;o)

8 3727
nico5038
3,080 Recognized Expert Specialist
You're close, just combine and use concatenation to get a result like:
Expand|Select|Wrap|Line Numbers
  1. If Me.estp > DLookup("amountauthorized", "Users", "UserName = '" & Me.text33 & "'") Then
  2.    MsgBox "Amount Over approval limit"
  3. end if
  4.  
Getting the idea ?

Nic;o)
Jan 24 '10 #2
toadmaster
45 New Member
Nic;

Thanks for the quick reply; however when I use your script I am getting the message box "Amount Over Approval Limit" pop up even though the figure in the estp text box on the form is less than amountauthorized(which is 200) in the table users.

Maybe I didn't explain myself well in the initial post. I want the script to look at the figure in estp(text field in the form) and compare it amountauthorized(which is 200 and in the users table).

The message box is supposed to pop up when the figure in estp is more than the amountauthorized.

I only threw in text33 as an extra check during the DLookup function(text33 is another text field which contains username and is exactly the same as the username field in the users table); call it the primary key field.

My main concern is to make sure the "if statement" works when estp is over the limit authorized in the amountauthorized field in the table.

I hope this explains it.

Thank you
Jan 24 '10 #3
nico5038
3,080 Recognized Expert Specialist
OK, guess we have a datatype problem.
1) Check that amountauthorized is a numeric field
2) Make the estp field also numeric or change "Me.estp" into "Val(Me.estp)"

Nic;o)
Jan 24 '10 #4
toadmaster
45 New Member
I changed estp to Val(Me.estp) and it works.

Thank you so much? You Rock!!!!!!!!!!!
Jan 24 '10 #5
nico5038
3,080 Recognized Expert Specialist
Perhaps better to set the estp field to numeric on the form, thus the user can't enter alphabetical characters.

Success with your application !

Nic;o)
Jan 24 '10 #6
toadmaster
45 New Member
I am also trying to use the DLookup function to check a table to see if a user is in there; if not refuse them access. The following is the code I am using but seems to just pop up the "Error Message" without really referencing the table
Expand|Select|Wrap|Line Numbers
  1. text33 = Environ("username")
  2. Text69 = DLookup("[Forename]&' '&[Surname]", "Users", "[Username] = text33")
  3. If text33 <> DLookup("[Username]", "Users", "[Username] = text33") Then
  4. MsgBox "You Are Not Authorized To Use This Form"
  5. Else
  6. If Val(Me.estp) > DLookup("amountauthorized", "Users", "UserName = '" & Me.text33 & "'") Then
  7.    MsgBox "Amount Over approval limit, Please Assign to Your Manager"
  8. Else
  9. With MailOutLook
  10.  
Feb 1 '10 #7
nico5038
3,080 Recognized Expert Specialist
You just need to test the DLOOKUP returning Null as value, indicating a user isn't found.
Something like:
Expand|Select|Wrap|Line Numbers
  1. If IsNull(DLookup("[Username]", "Users", "UserName = '" & Me.text33 & "'")) Then
  2.  
I did also change the WHERE part to get the username from the formfield Text33.

Tip:
Hope you'll understand when making this code why I always name my fields like "txtUsername"....

Nic;o)
Feb 1 '10 #8
toadmaster
45 New Member
This works, thank you so much
Feb 2 '10 #9

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

Similar topics

1
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application...
4
by: David B | last post by:
I have a Public function which creates a back up copy of a back end. It works fine with the source path and source file as C:\folder\etc. I thought I would try to store the paths in a table so...
2
by: Ronny Sigo | last post by:
Hello all, I already put the same question, only now I have more to tell ... Although I used this code before in the same routine (only the fieldname of the table differs) ___ at this point in the...
8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
2
by: jonvan20 | last post by:
I have been having trouble with a simple Dlookup command that was Reccommended to me by a nice fellow named Vic, On the other hand I have statements like this that wont run they give me a run time...
7
by: ApexData | last post by:
Hello I currently Link the FE/BE using the LinkTables Option and the Linked Table Manager. Any time I need to move the BE to another location, I have to go through this process over again. I...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
7
Breezwell
by: Breezwell | last post by:
This is probably a simple question for someone out there. I understand that the DLookup function takes has the following syntax: DLookup(expression,domain,) From what I have read, domain can...
7
by: WannabePrgmr | last post by:
What I am trying to do is on the click event of "Command167", run a Dlookup on the number that was just typed into "cboMoveTo1" and find the value located in the table "tblName" in the "Open/Closed"...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.