Solved

Access 2007 Verification Question on database tables

Posted on 2011-09-20
3
219 Views
Last Modified: 2012-05-12
I have attached a database that contains three Tables and three Data Entry Forms for the tables.  The Tables Are;  Point of Interest, Vehicles, and Weapons.  I need the capability to verify if a Driver License Number exists in the Point of Inrterest Table if the Driver License Number is entered in the Vehicle or Weapon Table.  I want an error message to appear when a user tries to enter a Driver License Number on the Vehicle or weapon table in the Driver License TextBox field.  If the Driver License Number exists allow the saveing of the record.  If the Driver License Number does not exist I want a mesage that one has entered a Driver License Number that does not exist.  How can this be done with VBA in ACcess and what property area should the coding be put on a form.  Should the arae be on an after update event or on a On-Click event?

I have attached a sample database I created from scratch real quickly.  CFould you maybe show me some coding how this can be done in VBA?

Thanks

jjc9809
Database2.accdb
0
Comment
Question by:jjc9809
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
pdebaets earned 500 total points
ID: 36570318
In the DriverLicenseNumber field BeforeUpdate event procedure on the Vehicles and Weapons form, put the following code:

Dim knt As Integer
knt = DCount("*", "PointOfInterest", "DriverLicenseNumber = '" & Me!DriverLicenseNumber & "'")
If knt > 0 Then
    '* Driver License Number exists on Point of Interest table.
Else
    MsgBox "Driver license does not exist on Point of Interest table. " & vbCrLf & vbCrLf & "Please press <ESC> to undo your changes."
    Cancel = True
End If

Open in new window

0
 

Author Comment

by:jjc9809
ID: 36570667
I ca't get this to work.  See my attachments where I placed the code ad tried to run it.  See if you can get it to work.

jjc9809
RunCode.jpg
CODE-DEBUG.jpg
0
 

Author Comment

by:jjc9809
ID: 36570710
Pdebaets,
 
I found my problem.  I used an incorrect name in the coding for PointOfInterest Table.  I renamed the table and removed the space in PointOfInterest.  I named the table PointOf Interest as the tablename but failed to indicate the space there so the computer was unable to find the table.

Thanks

This works.  

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

18 Experts available now in Live!

Get 1:1 Help Now