Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

when DLookup function returns a NULL

Posted on 1998-07-29
3
Medium Priority
?
233 Views
Last Modified: 2008-03-03
I am trying to write a sub that will loop through my tables to check if there is an entry in each table for a given subject number.  The DLookup function is the only way I know  to read data from other tables (besides the one the form is based on) but the sub stops running every time DLookup returns a null.  Should I be using a different function or is there a way to disable the error message that appears every time DLookup returns a null?
0
Comment
Question by:alina072998
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
devtha earned 300 total points
ID: 1957550
This example opens a Recordset and locates each record whose Title field satisfies the search criteria and copies it to the copy buffer.  The example prepares the record for subsequent editing, changes the job title, and saves the change using the Update method.

Dim Criteria As String, MyDB As Database, MySet As Recordset
Dim NewTitle As String
Criteria = "Title = 'Sales Representative'"      
' Set search criteria.
NewTitle = "Account Executive"      ' Set new job title.
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDB.OpenRecordset("Employees", DB_OPEN_DYNASET)  
' Create dynaset.
MySet.FindFirst Criteria      ' Find first occurrence.
Do Until MySet.NoMatch      ' Loop until no matching records.
      MySet.Edit                  ' Enable editing.
      MySet!Title = NewTitle      ' Change title.
      MySet.Update            ' Save changes.
      MySet.FindNext Criteria      ' Find next occurrence.
Loop                         ' End of loop.


0
 

Author Comment

by:alina072998
ID: 1957551
Thanks.  I think I get it.  To look through all of my tables for the same variable,
I would need to repeat the routine but change this:

Set MySet = MyDB.OpenRecordset("Employees", DB_OPEN_DYNASET)

statement, replacing the table name each time?
  
0
 
LVL 6

Expert Comment

by:devtha
ID: 1957552
YOU GOT IT EXACTLY. BULL's EYE
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

772 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