Solved

Checkbox true if criteria exists

Posted on 2014-01-08
2
438 Views
Last Modified: 2014-01-08
I have a checkbox on a form named chkbxCurrentCustomer.

I need code in the oncurrent event of the form to check the checkbox true if the contents of the field "FullName" exists in a field named "FullName" in tblCustomers.

Otherwise it should be false.

How can I do this?
0
Comment
Question by:SteveL13
2 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39765819
Try this:


chkMyBox = (Dcount("*", "tblCustomers", "FullName = " & chr(34) & Me.FullName & chr(34)) > 0)

Open in new window


(basically if the count of "FullName" in your table is greater than 0 based on the criteria, check the box otherwise the checkbox is false)
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39765822
So your form is not the based on tblCustomers, is that correct?

You could use something like:

Private Sub Form_Current:

  if me.[FullName] & "" = "" Then
      me.chkbxCurrentCustomer = false
  elseif DCOUNT("*", "tblCustomers", "[FullName] = '" & me.[FullName] & "'") > 0 Then
      me.chkbxCurrentCustomer = true
  Else
       me.chkbxCurrentCustomer = false
   End If

End Sub
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

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

914 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

14 Experts available now in Live!

Get 1:1 Help Now