Results 1 to 6 of 6
  1. #1
    MichealShinn is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    24

    Problem with DLookup

    Hi. This is my first posting. Thank you for your help.

    I work for a utility company. Some of our customers buy gas and electricity from us, some buy just one or the other.

    I have built a form that has a button on it that people can click after they enter a customer's account number. When they click the button, Access goes to two different tables (one for Electric and one for Gas) and looks up that customers' electric usage and gas usage from the last year in two local tables. The form has separate fields for the customer's electric usage, gas usage, electric revenue, etc, using DLookups (a separate DLookup for each field). If a customer buys only electricity from us, when Access gets to the DLookup to look for that customer's gas usage, I get an error number 94 because there is no gas record.

    How do I check to see if a record was found so it doesn't throw this error?



    Thank you again for all your help.

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You can use the nz function. The nz function take two arguments; the second argument specifies the value to return if the first is Null, otherwise it just returns the value of the first argument.

    In your case, you could use:

    [MyformField] = nz(Dlookup(...), "N/A")

    Which will return N/A if there is no gas record and the Dlookup return a Null.
    (That's how Dlookup works - it returns Null if no records match the criteria)

    John

  3. #3
    MichealShinn is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    24
    John,

    Thank you, that worked.

    There's another issue that I hope goes away overnight. This database lives on the network. People upstairs are opening the same database I am, but the changes I've made today (like adding the Nz to the DLookup) don't show up when they open the database at their computers. I've tried re-booting, shutting down, logging on as me, logging on as them, nothing.

    Have you ever heard about anything like this?

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    This sort of thing will almost always happen when the front-end (forms, queries, reports, etc) is in the same .mdb as the data, and has multiple users accessing that same file. Microsoft (and any good developer!) will tell you that when there are multiple users you should split you database into two parts - data tables in one part - the back end - , and everything else - the front end - in the other. (MS Access provides a utility to do it for you, but I don't know where it is in A2007).

    Once you have done that, put a copy of the front end on each user's own machine, with only the data on the network. The front end accesses the data through linked tables. That will usually resolve the problems you have been encountering, and it also allows you to have a copy of the front-end on your own machine for development. The down side is that every time you make changes, the users have to copy the amended front end to their own PC's, but IMO that is only a minor inconvenience.

    John

  5. #5
    MichealShinn is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    24

    That Didn't Work

    John,

    Thank you for your suggestion about splitting the database. Unfortunately, it didn't work.

    I split the database. I now have impacts_2007.accdb and impacts_2007_be.accdb. I went to a user's office and put a shortcut to impacts_2007.accdb on his desktop. Then, I opened that database on his computer. I got the Invalid Use of Null error message (which I fixed after your first message yesterday) and a table that I deleted this morning showed up and two new tables that I created yesterday didn't show up.

    Do you have any more suggestions?

    Micheal

  6. #6
    MichealShinn is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    24

    I got it working

    I got it working. Thank you for all your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DLookup problem
    By the_rock in forum Programming
    Replies: 3
    Last Post: 01-11-2012, 02:36 AM
  2. Dlookup problem
    By metronometro in forum Queries
    Replies: 1
    Last Post: 01-07-2012, 12:17 PM
  3. Using Dlookup problem
    By Lupson2011 in forum Access
    Replies: 5
    Last Post: 12-07-2011, 10:33 AM
  4. Newbie Dlookup problem
    By opopanax666 in forum Programming
    Replies: 7
    Last Post: 08-13-2010, 05:47 AM
  5. Dlookup problem
    By CalifDan in forum Reports
    Replies: 4
    Last Post: 12-09-2009, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums