user groups

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a simple database that will have 3 groups using it. I want to restrict
some of these used to just one "Form" and One to access to "All forms" I
wish to create a simple password form that will require the "GroupsName" and
"Password" for them to access their form. How many 'If and then " can you
use. e.g. "If Me![Password] = "ssulano" Then
DoCmd.OpenForm "ModifyInvoice"
Else
MsgBox "Incorrect password", 16, "Password"
DoCmd.Close
End If

Can I use two other "If" examples with different passwords and different
forms to be open?
Is this the best method or is another way perhaps better?
 
I don't know of a specific limit to how many If statements can be nested, but
if the code is properly structured, there shouldn't be more than about 3 or 4
deep (This is my personal opinion)
What you want can be accomplished with less code using a Select Case
statement:

Dim strFrmName As String

Select Case Me![Password]
Case "ssulano"
strFrmName = "ModifyInvoice"
Case "bizzaro"
strFrmName = "SomeOtherForm"
Case "flakey"
strFrmName = "AnyOldForm"
Case Else
strFrmName = vbNullString
End Select

If strFrmName = vbNullString Then
MsgBox "Incorrect password", vbCritical, "Password"
DoCmd.Close
Else
DoCmd.OpenForm strFrmName
End If

Notice I changed the 16 to vbCritical
It is always better both for performance and for readability to use
intrinsic constants then the value they represent. I have been coding in VBA
for 10 years and I had to look up the value 16 to see what the command was
going to show.
Imagine trying to determine what the value 35 would show.
 
Thanks, will give your suggestion a try

Klatuu said:
I don't know of a specific limit to how many If statements can be nested, but
if the code is properly structured, there shouldn't be more than about 3 or 4
deep (This is my personal opinion)
What you want can be accomplished with less code using a Select Case
statement:

Dim strFrmName As String

Select Case Me![Password]
Case "ssulano"
strFrmName = "ModifyInvoice"
Case "bizzaro"
strFrmName = "SomeOtherForm"
Case "flakey"
strFrmName = "AnyOldForm"
Case Else
strFrmName = vbNullString
End Select

If strFrmName = vbNullString Then
MsgBox "Incorrect password", vbCritical, "Password"
DoCmd.Close
Else
DoCmd.OpenForm strFrmName
End If

Notice I changed the 16 to vbCritical
It is always better both for performance and for readability to use
intrinsic constants then the value they represent. I have been coding in VBA
for 10 years and I had to look up the value 16 to see what the command was
going to show.
Imagine trying to determine what the value 35 would show.
--
Dave Hargis, Microsoft Access MVP


sandrao said:
I have a simple database that will have 3 groups using it. I want to restrict
some of these used to just one "Form" and One to access to "All forms" I
wish to create a simple password form that will require the "GroupsName" and
"Password" for them to access their form. How many 'If and then " can you
use. e.g. "If Me![Password] = "ssulano" Then
DoCmd.OpenForm "ModifyInvoice"
Else
MsgBox "Incorrect password", 16, "Password"
DoCmd.Close
End If

Can I use two other "If" examples with different passwords and different
forms to be open?
Is this the best method or is another way perhaps better?
 
Back
Top