Solved

Run time error Access 2010

Posted on 2013-12-30
2
567 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
ID: 39747172
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
ID: 39747175
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
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…

910 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

26 Experts available now in Live!

Get 1:1 Help Now