Solved

when DLookup function returns a NULL

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

679 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