Please review this code, (simple code) new with codes

Joe8915

Registered User.
Local time
Today, 14:37
Joined
Sep 9, 2002
Messages
820
Works great, but when I hit the number "3", (3 times in row) it will let me into the form. I want it to not let me in IF I don't know the password.

Where did I go wrong?

Private Sub Form_Load()
Dim pw As Variant

If InputBox("What is the password?", "Password") = "1" Then
Else
MsgBox "Invalid Password", vbCritical, "Sorry Charlie"
DoCmd.Close
If InputBox("What is the password?", "Password") = "2" Then
Else
MsgBox "Invalid Password", vbCritical, "Sorry Charlie"
DoCmd.Close
End If
End If


End Sub
 
I dislike the use of Input boxes but that is your choice.

Your IF was very confusing and not logical. Try this in the Forms OnOpen event...

Code:
Private Sub Form_Open()

    If InputBox("What is the password?", "Password") = "1" Then
        MsgBox "Correct Password", vbInformation, "Your in"
    Else
        MsgBox "Invalid Password", vbCritical, "Sorry Charlie"
        DoCmd.Close acForm, Me.name
        Exit Sub
    End If

End Sub
 
ghudson

That was the only way I could think, where the user can enter a password to get in. If you have a better idea, let me know. I just could not figure out any other way to do it.

Now I am trying to figure out, how to do it with each user. Do to each user must have a unique password.

We have about thirty users that have to have unique password, to view this form.

Thanks for the help, but if you tell me how you would do it, most likley I would go with your idea. I have been here long enough to value your opinion.
 
password

Joe,

For the amount of users how about having a seperate table with the users ID and passwords stored.

I have done this in the past. When clicking the button to open the protected form use a pop up form 1st. Here you can prompt the user to enter their ID and password and if correct continue to open the main form if incorrect you can prompt for another go or return the user to the original form.

This way you dont have to have unique code for each user and its easy to add or remove users from the password list. You could always go one further and have a log table which can store the details of who and when people accessed the protected form if you wanted.

hope this helps

ian
 
Sorry but i wanted to create a new thread

i dont know how to post a new thread/post
Can you tell me how? Thanks:confused:
 
iangirven

Ok, I like that idea. Can you give me example how you did that. I have created the table. Then I use a POP UP form, I got that, but now I have to have them enter a Password to go on. How did you make it, to prompt them to enter the password.
 
iangirven

I have this enter into a query Like [Enter password] & "*", but if the user does not enter anything, all records show up. Maybe Iam missing the idea here. Which would not be a first time.
 
password

Joe,

Basically you use will have a couple of unbound text boxes on the pop up window with a command button to enter the page, databse or whatever. On clicking this it will open up the relevant table and check to see if the persons ID matches the password. If it doesnt it wont let em in. Ive had to modify it slightly to protect the innocent (lol) but I think you should be able to get it working from here.

In addition to this you can add some sort of counter to allow several tries before locking out altogether. You could also have a seperate table to log the details of the person logging in.

anyway I hope this helps a bit.

best of look

Ian
BTW this is currently accessed by about 1200 different users each with their own ID and password. Granted its slightly modified as some of the users only have access to certain parts of the database.


eg.
Option Compare Database ' SYSTEM ENTRY FORM MODULE
Dim db As Database
Dim r As Recordset
Option Explicit
Private Sub Command8_Click()
On Error GoTo errorfix

Set db = CurrentDb
' Table personal1 is where the user ID and passwords are stored.

Set r = db.OpenRecordset("personal1")

r.MoveFirst
Do Until r.EOF
' This checks the user ID and password if a match is found it hides the password form and opens the next form

If pass1 = r![pasword one] And name1 = r![userID] Then
Visible = False
DoCmd.OpenForm ("Iform name here")
GoTo exit_sub
Else
r.MoveNext
End If
Loop
' if the details entered arent correct a message appears and in this case the database closes.
MsgBox "THE PASSWORD AND USER NAME DO NOT MATCH.THE DATABASE WILL NOW CLOSE"
DoCmd.quit
exit_sub:
Exit Sub

errorfix:
Resume exit_sub

End Sub
 
password query

Joe,

I assume you have used the query to compare the data entered by the user. As you have found it can cause problems. Stick with the VBA code and pop up form as you can format the text boxes so "*" is seen instead of the actual letters.

regards
Ian
 
Iangirven
Sound like you have your DB down to a science (on this password). I like it, but not sure if I can make it work. I will start ASAP. I have the suits all over me to get this down.

Which brings me to the next question or favor. How hard would it be, if you can send me a sample on how yours work.

Thanks for the quick response.
 
OK
Iangirven
I have set a table called = Tblpersonal1
with three Fields
1.userID.....autonumber
2.Password one..text
3.name1..text
One form name Iform
with the following fields
2 unbound.text boxes
1 command button

I just copy and past the code in.

of course that would of been to easy for me.
I did receive an error msg on "If pass1

So how far Iam I off?
 
password code

Joe,
sorry for the delay getting back to you
I have attached a copy of a basic password form. i have made some remarks for each part of the coding. I hope you find it useful. You may also want to have a look at the properties of the password textbox for the correct formatting.

it makes a nice change to be able to offer some help instead of asking for it. If you need any more info on this let me know.

regards

Ian
 

Attachments

sorry for the delay..............I am just glad you got back

WOW, Now that works GREAT. Now that is something.

Many thanks
 
IAN

Well it work great before I imported to my DB. But when I type in the password, it says type mismatch. So what did I do wrong?
 
Joe,
Its normally due to a variable expecting 1 type of data but receiving another. eg an interger receiving text etc. It could also be the code requires compiling or one of the references are missing.

If you could post a copy of your code or database Ill have a look at it and see if i can help.

regards

ian
 
ian

This is the only other code I have in the Database. I hope this helps. The only other code is where I pasted yours

Option Compare Database
Option Explicit


'needed to get original value of field b/4 change
Dim strOrigValue As String
'and value after change
Dim strNewValue As String
'


Private Sub FieldChange(strPK As String, strField As String)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' subprocedure to add information to the table tblCHANGES
'' called from a fields 'after update' event
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error GoTo FieldChange_ERR

Dim rst As Variant
'set recordset = to the table which I wish to add data to
Set rst = CurrentDb.OpenRecordset("tblCHANGESProclog")
With rst
.AddNew 'add new record
!fldUser = CurrentUser() ' \
!fldRecord = strPK ' \
!fldField = strField ' >add info
!fldOrigValue = strOrigValue ' /
!fldNewValue = strNewValue ' /
!fldTime = Now() '/
.Update 'save changes
End With
'close database and recordset (clean-up)
rst.Close
Set rst = Nothing

FieldChange_EXIT:
Exit Sub
FieldChange_ERR:
MsgBox Err.Description, , "error number: " & Err.Number & " - FieldChange Procedure"
Resume FieldChange_EXIT
End Sub


Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdFormChanes_Click()
DoCmd.OpenForm "frmChanges"
End Sub


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'the 2 following procedures are what you need to add to a fields events
Private Sub fldInfo_AfterUpdate()
'get new value (make sure not null)
strNewValue = Nz(fldInfo, "new value is NULL>")
'calling the fieldchange procedure
FieldChange ID, "fldInfo"
End Sub
Private Sub fldInfo_Enter()
'get original value (make sure not null)
strOrigValue = Nz(fldInfo, "<original value was NULL>")
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
additional code

Joe,

could you please post the code that includes the additions you ohave pasted into it. It would also help you could identify highlight the line of code that is causing the problem.

cheers
Ian
 

Users who are viewing this thread

Back
Top Bottom