473,796 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLookup from a query criteria trouble

21 New Member
[I'm new here]


Access 03

I'm currently having an issue using Dlookup when trying to reference a query (criteria syntax)

Currently I have 1 table, which is L_Emps (which contains Employee_ID as my key (numeric), First_Name, and Last_Name (as text).

My query is Query1 which is the following:

Expand|Select|Wrap|Line Numbers
  1. SELECT L_Emps.Employee_ID, L_Emps.First_Name, L_Emps.Last_Name
  2. FROM L_Emps
  3. WHERE (((L_Emps.Employee_ID)=[ID:]));
I have one form that is named L_EmpsForm. It is basically three bound fields that references Query1.

What I'm trying to do is have an onclick button return the ID that was returned from the query.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command6_Click()
  2.  
  3. ID = DLookup("[Employee_ID]", "[Query1]", "[Employee_ID]=" & [Forms]![L_EmpsForm]![Employee_ID])
  4.  
  5. MsgBox ID
  6.  
  7. End Sub 
This is just a test database to try to teach myself how to use DLookup, but it isn't going so well. I can get DLookup to work fine if I use a static query, but whenever I prompt for the input, I usually get the "You canceled the previous operation" error. I've read up that some of the field references could be off, but I'm unsure as to what exactly.

I know it is a tad redudant to have the Onclick button return the value that is obviously right in front of me when I run the form, but I actually plan on passing the table information into different directions once I actually figure out Dlookup.



Advice?


-DH22
Aug 29 '08
30 7284
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Well, I would not attempt to use Access for file deletion when the Windows environment provides the normal Explorer facilities to do so.

I attach a very simple demo (in Access 2003) based on what you have mentioned in the above posts but without active delete code. It is just a single-form database showing how you would feed a combo from a source query. In design view of the form you should have a look at the combo's After Update event code to see where the delete code would go.

However, if it was me I would not do this in Access anyhow.

-Stewart
Attached Files
File Type: zip Test Combo.zip (12.7 KB, 149 views)
Sep 4 '08 #11
DH22
21 New Member
I'd prefer not to do it with Access, either.

However, my problem is thus: My directory is huge, over thirty databases, one million+ files, and 500gb+ of information.

I need to be able to look up an image file and delete it. I will not know the directory or subdirectory in which the file will reside, though there are over fifty directories for each database with over thirty subdirectories for each (and climbing).

I'll only know the account number and suffix and have to find the image based on those two criteria.

Searching through such a huge directory takes windows forever. Access returns the value I am looking for quickly.

My options are limited: I cannot download anything and only have Access and Windows at my disposal.

I'm open to other suggestions, though.


[Edit]

Thank you for the sample database, Stewart. I really do appreciate your help. I did manage to get that far in with the query and form. As mentioned though, I have to hunt down which file I need by Account and Suffix, so having a gigantic list in the form wouldn't be feasiable. I have to restrict my form to just the results of the search, which is hopefully only one account number + suffix.

Expand|Select|Wrap|Line Numbers
  1. SELECT dbase.Directory, dbase.SubDirectory, dbase.Filename, dbase.Account_Number, dbase.Suffix, [Directory] & "\" & [SubDirectory] & "\" & [Filename] & ".txt" AS File
  2. FROM dbase
  3. WHERE (((dbase.Account_Number)=[Account:]) AND ((dbase.Suffix)=[Suffix:]));
So I still need the WHERE clause.

Am I making any sense? Heh. [/Edit]

-DH22
Sep 4 '08 #12
Stewart Ross
2,545 Recognized Expert Moderator Specialist
...in which case you need a cascaded combo box solution involving two combos, one to select the accounts and the other to select the files pertaining to that account only. I will see if I can modify the sample later to add this for you to see. I can't reproduce the thousands of filenames, though :-)
-Stewart
Sep 4 '08 #13
DH22
21 New Member
...in which case you need a cascaded combo box solution involving two combos, one to select the accounts and the other to select the files pertaining to that account only. I will see if I can modify the sample later to add this for you to see. I can't reproduce the thousands of filenames, though :-)
-Stewart

If it works with three files, it should work with a thousand, I'd image.

I was sort of thinking was it possible to have a form to retrieve the information, make it static long enough for a second form to use something (maybe Dlookup at that point, since it works with 'static' information).

But you understand where I am coming from, right, Stewart?

I basically need to restrict the range of data..

-DH22
Sep 4 '08 #14
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Oh ye of little faith... DLookup is, as I have said all along, not the right solution for this kind of application. See the attached sample DB duly updated and attached to this post.

-Stewart
Attached Files
File Type: zip Test Combo.zip (18.0 KB, 135 views)
Sep 4 '08 #15
Stewart Ross
2,545 Recognized Expert Moderator Specialist
By the way, this is not a complete solution to everything; if you need to filter the suffixes you can adopt a similar cascading approach to these using combos (or listboxes should you prefer) as necessary. I'll leave you to work this side of things out if it is needed...

-Stewart
Sep 4 '08 #16
DH22
21 New Member
Oh ye of little faith... DLookup is, as I have said all along, not the right solution for this kind of application. See the attached sample DB duly updated and attached to this post.

-Stewart

Okay, how do I narrow the account list down to just a specific account? We're working on close to one million account numbers as well. I cannot possibly expect them to go through the entire list looking for one, right?

I may just be confused and being frustrating, which if so, I humbly apologize!

I feel real close to a solution thanks to your assistance, but the long listing just doesn't feel.. "right", ya know?

[EDIT]

Ah, filtering, that could be another way to do what I'm looking for, yes?


Neverless, I am extremely appreciative of your help Stewart and if you're done with this topic, I'll be more than glad to press foward on my end and will not be offended. You've done alot of good, as is. I just need to.. tailor it, I guess.

If you're still curious, I won't be unappreciative for your continued input, either.

Thank you!

[/EDIT]

-DH22
Sep 4 '08 #17
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi again. You know that Access combo boxes character match as you type, right? So although a long list is presented to a user, the moment they type the first character the list reduces in size, and thereafter for every character that matches...

There will no doubt be other ways to reduce complexity - for example, selecting an account range to start with - but for me to know what would be best for you I'd need to know your application as well as you do - and I really, really don't know enough about it to come up with ideas like that...

Anyway, I'm more than happy to monitor the thread for further suggestions or inputs.

Cheers

-Stewart

ps combo box character matching can be turned off too, but it is on by default. And it shows the nearest complete match from the first character typed onwards - it is a really helpful facility IMHO.
Sep 4 '08 #18
DH22
21 New Member
Hmm, well, I could give more details and see what you may come up with, idea wise. I'm up for anything that keeps it simple on my end users.

What information would you need, Stewart? I typed a few long paragraphs to try and describe the situation, but then I realized trying to wade through that wouldn't be very nice and I won't do that to you.

Here's a summary:

I have tif files linked to accounts, that's all the database is.

Yes the database is used in conjunction with another application (web based), but that app is not designed to handle this situation.

I need to be able to delete these .tif files as appropriate.

I know nothing about the .tif file. The only information I have is the Account and Suffix (sorry for repeating myself). These two pieces of information are linked to the file, so when I search for one I find the other.

The *ideal* solution would be a very simple query for my end users that will let them pull up the information inside of Access and delete it using the VBA. The combo box works, but I think it'll make my end users uncomfortable and very unwilling to use the process.

If they could enter information into a prompted input box, have the values returned for verification that is what they are looking for, and use an Idiot Proof button that deletes the referenced file, that would be best. I.e. my obsession with Dlookup with that thought in mind.

That's pretty much it sums it up, I hope, Stewart. Anything else I can provide? I'd attach a sample database but it doesn't differ that much from the one you provided.

As you stated, I'm just trying to reduce complexity so that only a few records, tops, appear.

We're dealing with a very large amount of records. I don't even know if there would be a performance issue with having a combo box listing that amount of records at once.
Sep 4 '08 #19
DH22
21 New Member
Heh, I bet you're going to scold me for this one, but what do you think about this?


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2.  
  3. Mystr = InputBox("Enter Account Number")
  4.  
  5. MyAccount = DLookup("[Account_Number]", "[dbase]", "[Account_Number]=" & Mystr)
  6.  
  7. MsgBox MyAccount
  8.  
  9. End Sub
I can use the Inputbox to trigger Dlookup into returning the right information?

[EDIT]

Well, okay, I get why it doesn't work. I mean, it does work, but there's no promise the two fields will match, it'll return just the first thing that matches and put them together.. so it's a no go. Chalk it up to newbism. Heh.

[/EDIT]
Sep 4 '08 #20

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

Similar topics

1
20805
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one site could have many units. How do I have the DLookUp field value change to a newly calcuated field when I navigate through the units? please see example below: On the Form: A site can have many units.
4
21106
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("", "LookUpAppts", " = " & Forms!!NumofPeople) Can someone tell me how to add multiple criteria? I tried "And" but it doesn't seem to work.
7
2258
by: Tony Williams | last post by:
Does DLookup work in an expression in a query? I have this expression -(DLookUp("","tblmaintabs","= ")) Which works fine as a calculated control on a form but when I try to use it in a query as an expression I don't get any result. I want to use the Sum of the result in a query on which I will base a report. TIA Tony
8
4320
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 Klms Distance Jones Melbourne 500 Harrison Sydney 200 Ford Brisbane 700 Jones ...
2
2347
by: chris.thompson13 | last post by:
I am having a problem setting the criteria part of the DLookup method correctly and am consequently getting an error message. I have a database of staff duties, part of which is a query (qryDaily) that returns all staffs duties for a selected day.e.g. Fullname Duty Name1 E1 Name2 Sick Name3 Pwk N2
1
2435
by: MLH | last post by:
I have a query that looks up records in tblReturnReceipts and other related tables. One of the other tables is tblCorrespondence. The resulting dynaset consists of five records. Each has a unique field value and each has a unique field value. I would like to add an additional field to the query that performs a DLookup for some other stuff - using the query's value in the DLookup's criteria section. Of course, I'm having difficulty...
3
2457
by: hrreece | last post by:
I am trying to use the Dlookup expression in a macro to pull the value from the "Price" field in the following query. The query works fine and the Dlookup function did as well until I added a new field to the "Contracts" table called "ContractYear". SELECT Contracts.ID, Contracts.Commodity, Contracts.Date, Contracts.ContractYear, Contracts.Option, Contracts., Contracts.Bushels, Contracts.Price, Contracts. FROM Customer INNER JOIN Contracts...
2
3664
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 record with double or single quotes in the location description and click a button to see if Access can tell me the ID number and find its way back to the original record. When the text contains double quotes the FindFirst works but the Dloookup...
3
1394
by: Demosthenis | last post by:
Hello, I am trying to seto up a Dlookup in a query. My Dlookup field will retrieve data from a second query. The match criteria is the W field. This dlookup up process has to retrieve 24 different values from the second query (Query5). Unfortunatelly the function always brings the first value of the 2nd query for all the 24 fields. My formula is the Expr10: IIf(="Stock4";dLookUp("SumOfExpr2";"Query5";"=" & ".");). Is it something...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
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 we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.