Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check two values

Posted on 2013-12-30
7
Medium Priority
?
281 Views
Last Modified: 2013-12-30
Hi

I use Access 2010.

I need to make a label and image visible on a form if there are values in two specific fields within two separate tables.  If there are no values then the label and image will be invisible.

Basically the two fields are 'ContactID' and 'Complete'.  The ContactID is a text field and the 'Complete' field is a Yes/No field.

I have two forms - 'Form1' and 'Form2'.

In 'Form 1' I have two fields.  'ContactID' and 'Complete'.  I also have these fields in 'Form 2'.

When I open 'Form 1' I want to check if there's another 'ContactID' with the same ID in form2 and if it has the field 'Complete' ticked.  If it does, then it will display the label and img to show it's complete.  If it can't find the same 'ContactID' and the field 'Complete' isn't ticked, then it will not display the label and img.

Thanks for your help.
0
Comment
Question by:CptPicard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:PatHartman
ID: 39746883
Forms don't store data.  Tables store data.  If the same record is displayed on two forms, it should be the same unless you look in the instant that someone is updating one of them.

To avoid confusing users, it is usually best to have only one form open at a time so I am not at all sure what you are trying to accomplish.  What is the purpose of having two forms open to the same record?
0
 

Author Comment

by:CptPicard
ID: 39746926
There's two tables and two forms.

both table 1 and 2 share the same unique field called 'ContactID'.

So when I have my Form1 open which looks at the record source 'Table1', I want it to check if there's the same 'ContactID' and the 'Complete' tick box is checked in 'Table 2'.  If Table 2 does have the same ContactID and the Complete tick box is checked for this ContactID then I want form 1 to make the Complete label and image visible.  If Table 2 doesn't have the same ContactID and the Complete tick box ticked, then it will not display the label and image to show it's complete.
0
 
LVL 39

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 39747001
You can use a DLookup() get/check a value in another table but what will trigger the lookup?  Do you want to check when a record is displayed?  In that case you would put the DLookup() in the form's Current event.  That's sort of what your description sounds like.
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

Open in new window

0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

Author Comment

by:CptPicard
ID: 39747039
That's exactly what I needed.  Thank you.
0
 

Author Comment

by:CptPicard
ID: 39747054
One problem though.  when there isn't anything in ContactID I get an error message.

Run-time error '3075':
Syntax error (missing operator) in query expression 'ContactID = '.
0
 

Author Comment

by:CptPicard
ID: 39747076
Hope you can help?
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39747618
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

Open in new window

I substituted 0 for null.  You shouldn't have an ID = 0 if it is an autonumber.  If 0 is a potential value, then you would need to use an If to avoid doing the DLookup().
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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.

704 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