Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check two values

Posted on 2013-12-30
7
Medium Priority
?
283 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
  • 4
  • 3
7 Comments
 
LVL 40

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 40

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
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!

 

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 40

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

916 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