Ensure Checkbox has a value

le888

Registered User.
Local time
Today, 07:37
Joined
Dec 10, 2003
Messages
344
Need help on checkbox

Hi everyone,

Need help on checkbox. I have a form and a subform which is bounded to the main form. In the subform, I have checkbox. The question is : I want the user check at least on one checkbox before Exit the database. Is it possible? I have written some codes and it verifie only the first record in the subform. The code below works only when you have an no null on the first record.

Thanks,

Le


Here is my code:
-------------------------------------
Private Sub cmdExit_Click()


If MsgBox("Do you wish to save the changes and Exit ?", vbQuestion + vbYesNo) = vbYes Then

If (Me.subfrmTPMReqUpdate.Form.chbReqTPMRel) = 0 Then
MsgBox " You have to check at least on one requirement.", vbExclamation

Else
MsgBox " Data have saved!"
DoCmd.Close acForm, "frmClientUpdate"

End If

End If

End Sub
 
Try a DCount where the field represented by the checkbox = True. If it < 1, alert the user to the requirement.
 
Hi MikeAngelastro,

I'm not sure I understand. What is "DCount" and where I should put in my code? Thanks for your reply.

Le
 
"DCount" is a standard Access function. I suggest that you do a search for it in the Access Help facility. It will explain it better than I can.
 
Hi,

I think this should work but it returns an error.

I have put this in the top of my code :


Dim numReq As Integer


numReq = DCount("[Me.subfrmTPMReqUpdate.Form.txtReqName]", "qryTPMReqUpdate", [Me.subfrmTPMReqUpdate.Form.ReqTPMRelationships] >= 1)

This code returns an error. So, what's wrong? Please help.

Thanks again.

Le
 
DCount searches a recordset - you do NOT include references to the current form's class.

ie.

Code:
If DCount("MyFieldName", "MyTableName") > 0 Then
 
Thanks Guys!!! It has saved me a lot of time. I have never see so fast you guys solve the problem!! A+++.

Thanks again.


Le :D
 
Hi Guys,

Me again. Everythings seem O.K. But, I don't know why when I change the data, it seems don't works. It's like it didn't refresh.

Le :confused:

See my code:

If MsgBox("Do you wish to save" & _
"the changes and Exit ?", vbQuestion + vbYesNo) = vbYes Then

Me.subfrmTPMReqUpdate.Form.Refresh

If DCount("ReqName", "qryTPMReqUpdate", ReqTPMRelationships >= 1) > 0 Then
MsgBox " Data have saved!"

Else
MsgBox " You have to check at least on one Requirement" & _
" and on one Technology.", vbExclamation

End If
End If
 
Hi,

I think I know what's wrong. The code you gave me is O.K. But, I don't what to count all the records in this domain. I want is count a specific part in this domain. I mean :

Main Form TPM1

SubForm Req1 , Checkbox = 1
Req2 , Checkbox = 3
Req3 , Checkbox = 0

Number for Count should give me something like = 2 or True

Main Form TPM2

SubForm Req1 , Checkbox = 0
Req2 , Checkbox = 0
Req3 , Checkbox = 0
Req4 , Checkbox = 0

Number for Count should give me something like = 0 or False

Is it possible? Because using DCount, it count all the records.

Thanks,

Le
 

Users who are viewing this thread

Back
Top Bottom