473,785 Members | 2,220 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 #1
30 7281
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi DH22, and Welcome to Bytes!

There is nothing wrong with your syntax for the Dlookup. I am sure the problem is that you are trying to lookup a field value in a query, Query1 in this case, which has a parameter asking for data entry from the user ([ID:]). Not only is this unnecessary in the circumstances, it will cause a Dlookup failure, because within DLookup the JET database engine will not be able to interpret the parameter as a valid field.

Remove the parameter (the whole WHERE clause) from Query1 and see how you get on.

-Stewart
Aug 29 '08 #2
DH22
21 New Member
Hi DH22, and Welcome to Bytes!

There is nothing wrong with your syntax for the Dlookup. I am sure the problem is that you are trying to lookup a field value in a query, Query1 in this case, which has a parameter asking for data entry from the user ([ID:]). Not only is this unnecessary in the circumstances, it will cause a Dlookup failure, because within DLookup the JET database engine will not be able to interpret the parameter as a valid field.

Remove the parameter (the whole WHERE clause) from Query1 and see how you get on.

-Stewart

Hey, that did work, Stewart. Thank you! I'm still very fuzzy on the criteria, but I'm practicing.

However, the reason why I need the query is I will be setting up a Dlookup to use in conjunction with a delete function.

I'm trying to think of the best way to phrase this..

I have a database with records that point to files. Field 1 points to the directory, field 2 points to the sub directory, field 3 points to the file, field 4 points to the account number and 6 is the suffix.

I need the users to be able to input an account number and the suffix, pull up the matching records (indexes), and upon finding the one they wish to delete be able to press the button and have the file be deleted.

How do I set that up then if I can't use the form to call whatever the query tells it to bring foward?

I have the
Expand|Select|Wrap|Line Numbers
  1.  set objFSO = CreateObject("Scripting.FileSystemObject")
  2. objFSO.DeleteFile(strFilePath)
  3. WScript.Echo "Successfully deleted file" 
I wish to use to delete the file once it is found with the query, I just need to set strFilePath to field1 & field2 & field3 when the account number and suffix returns a hit.

Am I being clear? I hope so.

-DH22
Aug 29 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi DH22. I wouldn't use Dlookup for the purpose you mention; I'd use an unbound combo box instead (an unbound control is one that is not bound to an underlying field in a table or query). The rowsource of the combo would be a query based on the table you mention. You can use a calculated field in the query to combine the separate field values you mention into a single filepath you can pass to the delete code.

To run the delete after making a selection from the combo use the After Update event of the combo to run the delete file code based on the value of the combo.

Combo boxes in unbound form make very flexible lookup controls, as the multiple columns they can display can all be accessed in VBA code for whatever purposes you might need. In this case, you only need to list the filepaths, so one column should suffice.

-Stewart
Aug 29 '08 #4
DH22
21 New Member
Hi DH22. I wouldn't use Dlookup for the purpose you mention; I'd use an unbound combo box instead (an unbound control is one that is not bound to an underlying field in a table or query). The rowsource of the combo would be a query based on the table you mention. You can use a calculated field in the query to combine the separate field values you mention into a single filepath you can pass to the delete code.

To run the delete after making a selection from the combo use the After Update event of the combo to run the delete file code based on the value of the combo.

Combo boxes in unbound form make very flexible lookup controls, as the multiple columns they can display can all be accessed in VBA code for whatever purposes you might need. In this case, you only need to list the filepaths, so one column should suffice.

-Stewart

Stewart, I will search around to see if I can find some more details for that, but what I am after is very possible, right?
Sep 2 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Indeed so, DH22. Experiment a bit with combos and particularly the After Update event, which is fired whenever a user makes (or changes) a selection in the combo.

-Stewart
Sep 2 '08 #6
DH22
21 New Member
I firmly admit that at this second I'm clueless on how to use the combo box, but I'll figure it out.

Would it be possible for you to point to some reference material? I will be hitting google quite hard here, in a bit, as well.


-DH22
Sep 2 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
First of all, create an Access query which combines your separate fields into one overall filename for each file you want to delete. The calculated field is nothing more than a field in the Access query editor, something like this:

Filename: [Directory] & "\" & [subdir] & "\" and [filename] & "." & [suffix]

You may or may not need the slash marks and the dot - all depends on how your paths etc are stored.

Then, on a blank form use the Access combo box wizard and place a combo box on a form, basing it on the filename field of the query you just created.

Once this is done you can then explore how to use After Update to perform the actual delete if the combo box is not null - in other words if the user has not cleared the contents of the combo.

Search this site for examples of the use of After Update in Access - there are plenty of examples here.

Beyond that there is no real reference material I can give you - it is just a case of knowing what combos do, and combining this with code fired on the After Update event of the combo itself.

-Stewart
Sep 2 '08 #8
DH22
21 New Member
Stewart,

I will be doing just that. Thank you very much for your time and patience in this matter. Hopefully I'll figure it out. I've been using Access and VBA for a week and a half now, so I'm gaining steam.




-DH22
Sep 2 '08 #9
DH22
21 New Member
Stewart,


I'm not having much luck so far with the combo box (and frankly I'm not liking it very much, either. That's probably due to my lack of experience with it, though.)

While I work on learning to like the combo box, are there any other options you can recommend?



-DH22
Sep 3 '08 #10

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
21105
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
2346
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
2434
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
3662
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
1393
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
9647
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
9489
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
10162
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...
1
10100
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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
7509
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
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3665
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.