DelMONSTER23
01-12-2004, 08:52 AM
I have a database that will have users who have really never used computers before and therefore it is desired that they only see the main form on startup of the database and not the database window. I know how to do this using the tools/startup option and I found in a search how to do it in code (down below), but the problem is there will also be users who might need to come in and make changes. The following code only will take effect the second time a user under a certain user name opens the database since it is setting startup properties. My question is Is there anyway to control the show database window property depending on the username on the main form's onload event? (i already have used an api to get the username so I don't need help with that part) Thanks for any help.
Code:--------------------------------------------------------------------------------
Private Sub Form_Load()
If CurrentUser = "Admin" Then
SetStartupProperties "(none)", True
Else
SetStartupProperties "frmMain", False
End If
End Sub
Sub SetStartupProperties(strStartup As String, bAllow As Boolean)
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
ChangeProperty "StartupForm", DB_Text, strStartup
ChangeProperty "StartupShowDBWindow", DB_Boolean, bAllow
ChangeProperty "StartupShowStatusBar", DB_Boolean, bAllow
ChangeProperty "AllowBuiltinToolbars", DB_Boolean, True
ChangeProperty "AllowFullMenus", DB_Boolean, True
ChangeProperty "AllowBreakIntoCode", DB_Boolean, True
ChangeProperty "AllowSpecialKeys", DB_Boolean, bAllow
ChangeProperty "AllowBypassKey", DB_Boolean, bAllow
ChangeProperty "AllowToolbarChanges", DB_Boolean, True
End Sub
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
--------------------------------------------------------------------------------
Code:--------------------------------------------------------------------------------
Private Sub Form_Load()
If CurrentUser = "Admin" Then
SetStartupProperties "(none)", True
Else
SetStartupProperties "frmMain", False
End If
End Sub
Sub SetStartupProperties(strStartup As String, bAllow As Boolean)
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
ChangeProperty "StartupForm", DB_Text, strStartup
ChangeProperty "StartupShowDBWindow", DB_Boolean, bAllow
ChangeProperty "StartupShowStatusBar", DB_Boolean, bAllow
ChangeProperty "AllowBuiltinToolbars", DB_Boolean, True
ChangeProperty "AllowFullMenus", DB_Boolean, True
ChangeProperty "AllowBreakIntoCode", DB_Boolean, True
ChangeProperty "AllowSpecialKeys", DB_Boolean, bAllow
ChangeProperty "AllowBypassKey", DB_Boolean, bAllow
ChangeProperty "AllowToolbarChanges", DB_Boolean, True
End Sub
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
--------------------------------------------------------------------------------