Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Make checkbox true if certain situation exists

I have a form that has a checkbox.  I want the checkbox to be checked (true) if records exist in tblOutpurchase where the field EstN is equal to the field "txtRealEstN" on the form.  Here is my code for teh oncurrent event of the form which is not working.  Can someone spot the problem for me?

    If Len([tblOutsidePurchase]![EstN] & Me.realEstN & "\*.*") = 0 Then
        Me!chkbxHasOP = False
        Else
        Me!chkbxHasOP = True
    End If
0
SteveL13
Asked:
SteveL13
  • 10
  • 9
1 Solution
 
Rey Obrero (Capricorn1)Commented:
     'if field EstN is Number Data Type, us this

Me.chkbxHasOP= dcount("*","tblOutsidePurchase","EstN=" & me.txtRealEstN)> 0


     'if field EstN is Text Data Type, us this

Me.chkbxHasOP= dcount("*","tblOutsidePurchase","EstN='" & me.txtRealEstN & "'")> 0
0
 
SteveL13Author Commented:
I tried both but EstN is definitely a text field.  Neither one works.
0
 
SteveL13Author Commented:
Whoops.  I was wrong.  Every form record I open now has the checkbox checked using...

Me.chkbxHasOP= dcount("*","tblOutsidePurchase","EstN='" & me.txtRealEstN & "'")> 0

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
SteveL13Author Commented:
I only want the checkbox checked if a record exists in tblOutsidePurchase that has records in EstN that relate to the field "txtRealEstN" on the form "frmEstimateHeader" which is the form being opened that has the checkbox.
0
 
Rey Obrero (Capricorn1)Commented:
so it is working now?
0
 
Rey Obrero (Capricorn1)Commented:
what type of form do you have?
0
 
SteveL13Author Commented:
No.  No matter what record I open to on the form, the checkbox is checked even if no records exist in tblOutsidePurchase for the "txtRealEstN" on the form the checkbox is on.
0
 
SteveL13Author Commented:
I'm sorry.. I don't know what you mean by what type of form do I have.
0
 
Rey Obrero (Capricorn1)Commented:
what is the RecordSource of your form?
0
 
Rey Obrero (Capricorn1)Commented:
is your form Single, continuous, datasheet?
0
 
Rey Obrero (Capricorn1)Commented:
does the value in textbox "txtRealEstN" changed for every record?
0
 
SteveL13Author Commented:
Recordsource = tblMyEstimates
Is a single form
On the form, frmEstimateHeader, the textbox "txtRealEst" does change for every record in the table, "tblEstimateHeader"
0
 
Rey Obrero (Capricorn1)Commented:
ok.,
the Recordsource of the form frmEstimateHeader is tblMyEstimates ? is this correct?

how is the table "tblEstimateHeader" got involve here?
0
 
SteveL13Author Commented:
the Recordsource of the form frmEstimateHeader is tblMyEstimates ? is this correct?  YES

how is the table "tblEstimateHeader" got involve here?   You asked my what the recordsource of the form with the checbok is.
0
 
Rey Obrero (Capricorn1)Commented:
so you have a form/subform setup?
0
 
SteveL13Author Commented:
Yes... the main form is frmEstimateHeader.  The subform is frmOutpurchase.  If there are records in frmOutpurchase for the txtRealEstN the I want the checkbox on frmEstimateHeader to be checked.
0
 
Rey Obrero (Capricorn1)Commented:
ok. upload a copy of the db...
0
 
SteveL13Author Commented:
Ok.  See file.

Please note before you do anything.  tblOutpurchase has no records for SCL-168 which IS a record in tblMyEstimates.

So, when you open frmEstimateHeader, for estimate SCL-168, the checkbox "chkbxHasOP" should NOT be checked because thare are NO records in tblOutpurchase for estimate SCL-168.  But what is happening is that by openeing the form frmEstimateHeader to that record, it is checking the checkbox and should not be doing so since there are no records in tblOutpurchase for the estimate.

But if you go to Est SCL-162 in the form frmEstimateHeader the checkbox SHOULD be checked because there are records in tblOutpurchase for that estimate.
Example.accdb
0
 
SteveL13Author Commented:
I think I found the problem.  Here is what I have now based on your first suggestion: (note the =0 instead of >0).  Plus I switched the True and False from my first question.


    If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
        Me!chkbxHasOP = True
        Else
        Me!chkbxHasOP = False
    End If
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now