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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open another form using passwords

Status
Not open for further replies.

tazibc

Instructor
Oct 5, 2007
66
GB
Pls can someone help....
I have created a form called compliance database and I use a password form which opens the compliance form with the code below:-
Private Sub Command5_Click()
Dim strUser As String
Username.SetFocus
strUser = Username
If strUser = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database", , , "[Service Centre / Satellite] = 'Basingstoke'", , , strUser
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub

I have opened the crystal compliance database form and selected save as and renamed the form as belfast, so now I have two forms one compliance and the second belfast is there any way I can incorporate the second form which will only open if another pass word was inserted. how would I add it to the already existing code.
 
An ELSEIF statement?

Also, the way your code is set up you could just open the same form but with different criteria if you want to display something different.

Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
so where would the else if statement go would I just copy the existing code and change the form and pasword details at the end for example:-

Private Sub Command5_Click()
Dim strUser As String
Username.SetFocus
strUser = Username
If strUser = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database", , , "[Service Centre / Satellite] = 'Basingstoke'", , , strUser
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub
ELSE IF
Private Sub Command5_Click()
Dim strUser As String
Username.SetFocus
strUser = Username
If strUser = "user2" And Password = "user2" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Belfast", , , "[Service Centre / Satellite] = 'Belfast'", , , strUser
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub

is this the correct code
 
If you're going to do it like this then something more like:
Code:
Private Sub Command5_Click()
Dim strUser As String
Username.SetFocus
strUser = Username
If strUser = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database", , , "[Service Centre / Satellite] = 'Basingstoke'", , , strUser
ElseIf strUser = "user2" And Password = "user2" then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Belfast", , , "[Service Centre / Satellite] = 'Belfast'", , , strUser
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub
Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
is this the correct code
No.
You really have to learn the basis of VBA.
 
harley thats woked a treat thanks buddy
 
Glad to help [smile]

It might also (as PHV pointed out) be worth doing some reading up on some of the concepts of programming in VBA, specifically for this example, control statements.

Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top