Solved

Run time error Access 2010

Posted on 2013-12-30
2
565 Views
Last Modified: 2013-12-30
When I put the below in my forms Current event

----------------
If DLookup("TickBox","table2", "ContactID = " & Me.ContactID) = True Then
    Me.lblComplete.Visible = True
    Me.Image.Visible = True
Else
    Me.lblComplete.Visible = False
    Me.Image.Visible = False
End If
--------------

I get the following error message when I try adding a new record because the 'ContactID' field is empty.  Can anyone advice?

-------------------
Run-time error '3075':
Syntax error (missing operator) in query expression 'ContactID = '.
------------------
0
Comment
Question by:CptPicard
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
You can check for a New Record:

If Me.NewRecord Then
  'do something here
Else
  If DLookup("TickBox","table2", "ContactID = " & Me.ContactID) = True Then
    Me.lblComplete.Visible = True
    Me.Image.Visible = True
  Else
    Me.lblComplete.Visible = False
    Me.Image.Visible = False
  End If
End If

Or you can use the Nz function:

 If DLookup("TickBox","table2", "ContactID = " & Nz(Me.ContactID,0)) = True Then
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
or

If DLookup("TickBox","table2", "ContactID = " & Nz(Me.ContactID,0) ) = True Then
    Me.lblComplete.Visible = True
    Me.Image.Visible = True
Else
    Me.lblComplete.Visible = False
    Me.Image.Visible = False
End If
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

Suggested Solutions

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now