Solved

Check two values

Posted on 2013-12-30
7
267 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 34

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 34

Accepted Solution

by:
PatHartman earned 500 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 34

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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