Solved

DLookup error handling

Posted on 2002-07-29
8
528 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now