Solved

DLookup error handling

Posted on 2002-07-29
8
532 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now