Solved

Check two values

Posted on 2013-12-30
7
270 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

929 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

10 Experts available now in Live!

Get 1:1 Help Now