Problem with code for checkbox password, incorrect password required first???

Blue 08 R6

New member
Local time
Today, 22:03
Joined
Dec 17, 2009
Messages
8
Hi guys and girls,

Im having an issue with unlocking records for editing.

I have a check box on a form that is selected by our accounts dept and when it is checked and the focus is taken away from that record then it is locked for editing and deletion.

See code:

Code:
Private Sub Form_Current()
If Me.Check34 = True Then
Me.AllowAdditions = True
Me.AllowDeletions = False
Me.AllowEdits = False
Else
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True

End If
End Sub

Now I have added a unlock button at the bottom of the form that requires a password to be entered to allow any editing or deletions of a record by authorised personnel.

See code:

Code:
Private Sub ALLOWEDITBUTTONS_Click()
On Error GoTo Err_ALLOWEDITBUTTONS_Click
Retry:
Dim strInput As String
strInput = InputBox("Please Enter the Password", "Enter Password")
If strInput = "ACCOUNTS" Then
           If Me.Check34 = True Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
If MsgBox("You entered the wrong password. Do you wish to try again?", vbQuestion + vbYesNo, "Password Error") = vbYes Then
GoTo Retry
End If
End If
Exit_ALLOWEDITBUTTONS_Click:
Exit Sub
Err_ALLOWEDITBUTTONS_Click:
MsgBox Err.Description
Resume Exit_ALLOWEDITBUTTONS_Click
End Sub

The issue i am having is that if the correct password is entered the first time then the record is still locked for editing and deletion.

You physically have to enter an incorrect password and then click retry and enter the correct password for it to unlock the record.

Can anyone see what I have wrong in my code that would be causing the issue or having to enter an incorrect and then the correct password for it to work?

Also on an other note you will see the password is set to ACCOUNTS when entered into the input field it is incorrect, for some reason it is only picking up ACCOUNT (with out the S) as the correct password, missing out the last character happens for any word I set as the password.

Any thoughts on that?

Thank you in advance

Adam
 
Had a quick look:
{Try}

Code:
On Error GoTo Err_ALLOWEDITBUTTONS_Click
Retry:
Dim strInput As String
strInput = InputBox("Please Enter the Password", "Enter Password")
If strInput = "ACCOUNTS" Then
If Me.Check34 = True Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
Else
If MsgBox("You entered the wrong password. Do you wish to try again?", vbQuestion + vbYesNo, "Password Error") = vbYes Then
GoTo Retry
Else
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
End If
End If
Exit_ALLOWEDITBUTTONS_Click:
Exit Sub
Err_ALLOWEDITBUTTONS_Click:
MsgBox Err.Description
Resume Exit_ALLOWEDITBUTTONS_Click
 
Cheers DCB your a champ.

I did have something similar earlier but did not have the else statment for the conditions where you have put it.

I have changed the "Me.AllowAdditions = False" to = True though as I need them to be able to enter new records.

Thanks again for your help.

Adam
 
Hi,

Try this-
Code:
Private Sub ALLOWEDITBUTTONS_Click()
    On Error GoTo Err_ALLOWEDITBUTTONS_Click

[COLOR="SeaGreen"]'##SET UP VARIABLES##[/COLOR]
    Dim strPW As String
    Dim strInput As String

[COLOR="SeaGreen"]'##SET UP PASSWORD##[/COLOR]
    strPW = "ACCOUNTS"

[COLOR="SeaGreen"]'##RE DO POINT##[/COLOR]
Retry:

[COLOR="SeaGreen"]'##DISPLAY THE INPUT BOX##[/COLOR]
    strInput = InputBox("Please Enter the Password", "Enter Password")

[COLOR="SeaGreen"]'##CHECK FOR CORRECT PASSWORD. IF PASSWORD DOES NOT##[/COLOR]
[COLOR="SeaGreen"]'##MATCH, RETRY OTHERWISE CARRY ON##[/COLOR]
    If strInput <> strPW Then
        If MsgBox("You entered the wrong password. Do you wish to try again?", _
        vbQuestion + vbYesNo, "Password Error") = vbYes Then
            GoTo Retry
        Else
[COLOR="SeaGreen"]'##IF CHECHBOX IS TICKED, ALLOW EDITING##[/COLOR]
            If Me.Check34 = True Then
                Me.AllowAdditions = True
                Me.AllowDeletions = True
                Me.AllowEdits = True
                Exit Sub
[COLOR="SeaGreen"]'##OTHERWISE DISPLAY MESSAGE##[/COLOR]
            Else
                MsgBox ("Editing not allowed")
                Exit Sub
            End If
        End If
    End If
Exit_ALLOWEDITBUTTONS_Click:
    Exit Sub
Err_ALLOWEDITBUTTONS_Click:
    MsgBox Err.Description
    Resume Exit_ALLOWEDITBUTTONS_Click
End Sub

HTH


nidge
 
Cool
Have a good one

Did see my mistake on the allowadditions .... not very cleva....
 
Thanks for all the help peeps,

Im still having a slight problem though.

When i transfer the data base from my local machine to the server the password and check box conditions no longer apply.

Is this due to the ME. statement?

Im fairly new to this so any help would be good.

Should I use the name of the actual form to be locked instead of the ME. statement?

CHeers

Adam

Also whilst im going and as not to start an other thread. How am I able to automatically fill a text box on a form with the values in a field on a query.

I have tried
Code:
=[QRY WTS & Invoiced V PO Value]![Remaining Value]
but it only returns #Name?

I require this so that when they are at the record in question on the form they can see at a glance what value is left against that job.

Thanks again
 
When i transfer the data base from my local machine to the server the password and check box conditions no longer apply.
As in do not work?

Is this due to the ME. statement?
The Me statement refers to the form that the code is on - badly pu but lets leave it hanging for a while

Should I use the name of the actual form to be locked instead of the ME. statement? - You are saying that your code is not part of the form you wish to effect?

As for the other question - have a look at DLookup
 
Regarding the use on the server problem, I seem to remember that "True" should be changed to "-1" (and similarly "False" to "0") when using checkboxes in SQL, but other than that they should work. Might be worth a try though.

To set the text box on the form with a database value you either need to (1) bind the form to a recordset, or (2) use a domain lookup, or (3) call a recordset object and set text box value in VBA after some event (Form_Load maybe)


Examples:

(1) Form Properties, Record Source, "Query1", then set Control Source of the text box. You can sum values in a second text box using =sum([text1])

(2) Control Source of text box = DLookup("sum([Remaining Value])","Query1","Invoiced=-1")

(3) set rs=currentdb.openrecordset("select sum([Remaining Value]) from Query1"), me.txtBox = rs(0)
 
Hmmm - Server
Are you running the db as a FE/BE or running on a TSQL, PGSQL,MSQL,MySQL
Each of these have their own little changes - or rather drivers

stevemanser has mentioned the -1,0 this for example depends on the translation of the driver..... I often use PGSQL and the standard ODBC driver does handle the True False Boolean

Also watch out with the dlookup usage on sql servers! Have a quick google on this issue.

I suppose what I am saying is could you give us a bit more info on the architecture that you plan to dist in and we will be able to give you some better ideas (hopefully)
 

Users who are viewing this thread

Back
Top Bottom