Solved

DLookup error handling

Posted on 2002-07-29
8
549 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
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 100 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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