Solved

DLookup error handling

Posted on 2002-07-29
8
538 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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