?
Solved

DLookup error handling

Posted on 2002-07-29
8
Medium Priority
?
607 Views
Last Modified: 2012-05-04
I have a form that takes an order number.  I am taking that order number, and using it to grab certain values within a table, as follows:

dlookup("FieldNameHere", "tableNameHere", "val1 = " & orderNumberFromForm)

but if the order number from the form is actually bad data, it throws an error and quite the entire application.  Im wondering if anyone knows a fix for this, or perhaps a similiar function to dlookup that isnt quite as testy to work with?

The entire purpose of this is i need to get the total value of certain fields in the form.  So if i enter order number 1, and it has 5 records related to that order, i need to find the total value of the price field within that particular order.  I played with sum and dSum as well, but apparently im dim, cause i cant get anything working heh heh.
0
Comment
Question by:Hooligan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:knuckle05
ID: 7186216
Try a condition like the following

If IsNumeric(orderNumberFromForm) And Not IsNull(orderNumberFromForm) then
         dlookup "FieldNameHere", "tableNameHere", "val1= " & orderNumberFromForm)

else

     msgbox("Bad Data")
end if

You have to test your data before you perform your DLookup on the table...
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7186258
I normally don't need such a DLOOKUP as I just place a combobox with:
select distinct ordernumber from tblOrder;

In the AfterUpdate you can access the Orderdata that will always exist....

Nic;o)
0
 
LVL 2

Author Comment

by:Hooligan
ID: 7186288
youll have to forgive me, i worded that completly wrong.  I spent all weekend moving, so bear with me heh heh.

The value returned from the table, if it is null, it throws an error.  I cant test for it until i return it, and by that time its already errored out.  The problem is the way the DB was setup originally, i know.  but i didnt create it, im just trying to make some changes to it.  I could go back and change each null field in the table, then add an input rule, but for other reasons thats not feasable, as it would mean rebuilding the entire DB, something we are trying to avoid.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Hooligan
ID: 7186293
nico im trying to do all this within a form, a sub-form actually, is it possible to make an sql call in a subform?

I have about 0 expierience working with access as a front end, so if my quiestions seem silly, forgive me heh heh.  Ill take backend with ASP or VB anyday to this lol.
0
 
LVL 5

Expert Comment

by:KMAN
ID: 7186296
Create a query that has an expression on the field that contains the NULLs.  In the expression, Use NZ() or IIF() to convert the NULL values to something like "" or "Null" in order to interrogate after a successful DLookUp().

K
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 300 total points
ID: 7186338
The SQL effectively is "behind" the combobox and can be added also on a subform.
When you need multiple fields, you can even create a sub-sub-form with the fields and use the link fields to automatically display the sub-sub-form with the synchronized data.

Nic;o)
0
 
LVL 2

Author Comment

by:Hooligan
ID: 7195886
My apoloies for taking so long to accept an answer, I hadnt realized i didnt heh heh.

nico your solution isnt exactly what I did, but it lead to the solution i used for that particular problem.  Im still going to have to use lookups and probably dsum in several other forms tho, so ill prolly be back asking this exact same question again eventually heh heh
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7195920
We'll be waiting at EE ;-)

Success !

Nic;o)
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question