SteveL13
asked on
Make checkbox checked on 1nd form when 2nd form is closed
I have the following code in a close event of form 2. It is supposed to be checking a checkbox on form 1 (frmEstimateHeader") as true (or false) if the criteria is met. But it is not working. What am I doing wrong?
If Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
Forms!frmEstimateHeader.ch kbxHasOP.V alue = False
End If
If Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0 Then
Forms!frmEstimateHeader.ch kbxHasOP.V alue = True
End If
If Forms!frmEstimateHeader.ch
Forms!frmEstimateHeader.ch
End If
If Forms!frmEstimateHeader.ch
Forms!frmEstimateHeader.ch
End If
just use this one line
Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0
Forms!frmEstimateHeader.ch
ASKER
Neither of these suggestions worked.
are you getting an error?
I don't normally use wildcards in my domain functions. Does tblOutPurchase have an autonumber field? If so, try somethin like:
DCount("ID", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'")
Also, is txtRealEstN a numeric value, or a string. If it is numeric, try:
DCount("ID", "tblOutPurchase", "EstN=" & Me.txtRealEstN)
DCount("ID", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'")
Also, is txtRealEstN a numeric value, or a string. If it is numeric, try:
DCount("ID", "tblOutPurchase", "EstN=" & Me.txtRealEstN)
Why are you trying to set a Check box with the value of what is apparently a numeric field ... and it's count ?
mx
mx
ASKER
txtRealEstN is a text field.
All I want to do is check the checkbox if there are any records in tblOutpurchase that relate to the key field, EstN where the form field is txtRealEstN
All I want to do is check the checkbox if there are any records in tblOutpurchase that relate to the key field, EstN where the form field is txtRealEstN
ASKER
I am not getting an error.
this should do it, just one line
Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0
check the codes you are using
Forms!frmEstimateHeader.ch
check the codes you are using
ASKER
Didn't work. Here is what I am using in the onload event of frmEstimateHeader which is working perfectly. If a record exists intblOutpurchase related to the key field, the checkbox is checked. If no records exist then the checkbox is not checked. AllI want to have happen is this same logic when the 2nd form is closed.
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
Me!chkbxHasOP = False
End If
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0 Then
Me!chkbxHasOP = True
End If
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
Me!chkbxHasOP = False
End If
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0 Then
Me!chkbxHasOP = True
End If
place this in the close event of 2nd form
Forms!frmEstimateHeader.se tfocus
Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0
Forms!frmEstimateHeader.se
Forms!frmEstimateHeader.ch
ASKER
Did not work. If I delete the record(s) in tblOutpurchase related to the key field and then close form 2, the checkbox on form 1 is still checked and should not be checked.
Forms!frmEstimateHeader.se
Forms!frmEstimateHeader.ch
Forms!frmEstimateHeader.re
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is driving me crazy. I put this in the activate event of code 1:
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
Me!chkbxHasOP = False
End If
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0 Then
Me!chkbxHasOP = True
End If
And I put this in the onclode event of form 2:
Forms!frmEstimateHeader.Se tFocus
Forms!frmEstimateHeader.ch kbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0
Forms!frmEstimateHeader.Re query
And it is still not working correctly when the records are deleted from tblOutsidePurchases.
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") = 0 Then
Me!chkbxHasOP = False
End If
If Me.chkbxHasOP = DCount("*", "tblOutPurchase", "EstN='" & Me.txtRealEstN & "'") > 0 Then
Me!chkbxHasOP = True
End If
And I put this in the onclode event of form 2:
Forms!frmEstimateHeader.Se
Forms!frmEstimateHeader.ch
Forms!frmEstimateHeader.Re
And it is still not working correctly when the records are deleted from tblOutsidePurchases.
upload a copy of the db. (.mdb version)
Private Sub Form_Close
Forms!frmEstimateHeader.ch
End Sub
In Access, any non-zero number will evaluate to True