Solved

when DLookup function returns a NULL

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

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

860 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