Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Procedure Not Working Correctly 1

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
Good afternoon, folks. I have a table of users, tblAuthorizedUsers. In the table I have a text field, LogOn, and a checkbox, ApdCCD. I have a main form, and on that form I have a command button, for approval, and in the OnClick procedure I am try to run a validity test to see if the checkbox, for the current LogOn user, is true or not. When I click the command button, my logon entered in the textbox and todays date is entered in another, despite the fact that the checkbox ApdCCD is not checked for me. This is my OnClick code:
If DCount("[LogOn]", "tblAuthorizedUsers", "[LogOn]='" & fOSUserName() & "'") = 0 Then
MsgBox "You Are Not an Authorized User."
Me.Undo
'Delete wrong entered users
Me!CCDApproved.SetFocus
'Re-Enter Approval, same field
Else
'Valid user test, Is a valid user
If DCount("[LogOn]", "tblAuthorizedUsers", "[ApdCCD] = True") = 0 Then
MsgBox "You Are Not Authorized To Approve This Section."
Me.Undo
'Delete wrong section users
Me!CCDApproved.SetFocus
'Re-Enter Approval, same field
Else
'The User is Authorized
Me.CCDApprovedBy = fOSUserName()
'Enter LogOn in Approved By textbox
Me.CCDDate = Date
'Enter Today's Date in the Date textbox
Me.CCDComments.SetFocus
'Set Focus on Comment textbox
End If
End If
The first DCount statement is working correctly, it is the second Dcount statement that should be stopping me, because I do not have the ApdCCD checkbox checked, but it is not stopping me. Can anyone see what is wrong with this procedure? Thank you in advance for any assistance.
 
Try changing "True" to -1. A check boxes value is 0 or -1.

Hope this works!

Brenda
 
Thank you for the assistance, Brenda. I tried -1 and got the same thing, as well as did 0. Then I tried 1 and then everthing was block. That was the confusing part.
Any ideas on that one? Could this have anything to do with using two DCounts in one statement? Thank you again for the assistance.
 
Thank you again for the assistance, Brenda. The entire OnClick procedure is at the top of this post. I figured that no one want to see the
Private Sub CCDApproved_Click()
On Error GoTo Err_CCDApproved_Click
stuff but I already put everything in the first post, including some explanations of what is going on. I really appreciate the help, if there is anything else I can do or send you please let me know. It is 5:00 here and they are starting to shutdown the power in this plant so I am getting out of here. Thank you again for the help, this little bug is starting to get to me.
 
Sorry, I was daydreaming when I asked you to post the code :) When you debug, what value does Access say the check box has, 0 or -1? I can't imagine that it has anything to do with having 2 Dcounts. If you want to send me the entier application (if no one else can help) I would be happy to debug it for you and try and figure out what is going on. misty30706@aol.com
 
guest4,
There is nothing in your 2nd DCount statement to identify which user's checkbox you are evaluating - so my guess is Access is evaluating either the first or last checkbox in the table. Try this instead:

Code:
If DCount("[LogOn]", "tblAuthorizedUsers", "[LogOn]='" & fOSUserName() & "' AND [ApdCCD] = True") = 0 Then

HTH...

Ken S.
 
Check that. Right solution, bad explanation. Your 2nd DCount is counting all the records in the table where the checkbox value is True. As long as any record has a True checkbox, the statement will evaluate as false and your MsgBox will not pop. That's why you need to test for both user AND checkbox value in your 2nd DCount.

Oops, I misspelled your handle in my previous post quest4. Sorry.

Ken S.
 
You the man, Ken. It works. I thought that DCount was holding the count, that was why when I put in a 1 I would get the message, but the more I think of it the more I realize that you are right. Thank you very much for the assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top