Solved

when DLookup function returns a NULL

Posted on 1998-07-29
3
226 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 100 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

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.

Question has a verified solution.

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

Suggested Solutions

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

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

22 Experts available now in Live!

Get 1:1 Help Now