By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,461 Members | 2,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,461 IT Pros & Developers. It's quick & easy.

Customizing Front Ends

100+
P: 166
Hello,

Recently I split my DB and I would like for each FE to be customized so that the user will only see what they need to access. I do not use a log in to authenticate users so I wanted to know if I could just make a copy of the FE and then customize a copy for each user.

I appreciate the input
Feb 17 '09 #1
Share this Question
Share on Google+
5 Replies


Expert Mod 2.5K+
P: 2,545
You can customise different front ends for different users or groups of users as you wish, although developing an individual database for each user seems very labour-intensive to me.

It's also possible to develop custom user settings tables (quite independent of the limited user security in Access itself) which you can then use to implement a custom front-end. That way you can present different options to users depending on the network log-in name of the current user (easily found using system functions).

There are any number of possibilities for further development, limited only by your time and imagination...

-Stewart
Feb 17 '09 #2

100+
P: 166
Thanks for the response Stewart. I have just one DB, but several users. Currently I am using the switchboard list for users to access what they need but i would like to limit that.

In another DB I developed, I am using a login to authenticate users and determine what they see, so I know this way is effective. I just don't have it for my production DB as yet. So I guess my options are to develop using the log in authentication or customize each FE.
Feb 17 '09 #3

NeoPa
Expert Mod 15k+
P: 31,398
To save having to manage the logging in yourself, you could get the username from Windows (if that's right for what you want to do). This function should help with that :
Expand|Select|Wrap|Line Numbers
  1. 'GetUser returns the user's logged on name.
  2. Public Function GetUser() As String
  3.     Dim strUserKey As String
  4.  
  5.     If Environ("OS") = "Windows_NT" Then
  6.         strUserKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
  7.         GetUser = RegRead(conHKLM, strUserKey, "DefaultUserName")
  8.     Else
  9.         'Windows (95, 98 or ME)
  10.         GetUser = Environ("UserName")
  11.     End If
  12. End Function
PS. I strongly recommend the approach advocated by Stewart. Managing various different databases for this reason would be against your best interest.
Feb 17 '09 #4

Expert 100+
P: 1,287
Here's some code I use from Allen Browne, which he notes is safter than testing Environ().

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
  2.     "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  3.  
  4. Public Function GetNetworkUserName() As String
  5. On Error GoTo Err_Handler
  6.     'Purpose:   Returns the network login name
  7.     'Return:    The name, or "{Unknown}" on error.
  8.     'Note:      Safer than testing Environ().
  9.     Dim lngLen As Long
  10.     Dim lngX As Long
  11.     Dim strUserName As String
  12.  
  13.     strUserName = String$(254, 0&)
  14.     lngLen = 255&
  15.     lngX = apiGetUserName(strUserName, lngLen)
  16.     If (lngX > 0&) Then
  17.         strUserName = Left$(strUserName, lngLen - 1&)
  18.     End If
  19.  
  20.     If strUserName <> vbNullString Then
  21.         GetNetworkUserName = strUserName
  22.     Else
  23.         GetNetworkUserName = "{unknown}"
  24.     End If
  25.  
  26. Exit_Handler:
  27.     Exit Function
  28.  
  29. Err_Handler:
  30.     Call LogError(Err.number, Err.Description, conMod & ".fOSUserName")
  31.     Resume Exit_Handler
  32. End Function
I also keep each user's username in a table, along with which type of permissions they should have, User or Manager. Then I open the appropriate menu and forms for thier user type.
Feb 17 '09 #5

NeoPa
Expert Mod 15k+
P: 31,398
Usage of Environ() (which is quite risky as a user can change it) was restricted in my code to when running on pre-NT based Windows.

Unfortunately, the OS function call in the NT side was a call to a module which I didn't include (oops). I did scan it before posting - but missed this one :(

I'll include the other module, just in case of interest, but Chip's code is probably quite adequate instead (and doesn't require a separate module.

Module - modOS.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'Windows API Variable Prefixes
  5. 'cb = Count of Bytes (32-bit)
  6. 'w  = Word (16-bit)
  7. 'dw = Double Word (32-bit)
  8. 'lp = Long Pointer (32-bit)
  9. 'b  = Boolean (32-bit)
  10. 'h  = Handle (32-bit)
  11. 'ul = Unsigned Long (32-bit)
  12.  
  13. Public Const conHKCR = &H80000000
  14. Public Const conHKCU = &H80000001
  15. Public Const conHKLM = &H80000002
  16. Public Const conHKU = &H80000003
  17. Public Const conStandardRightsAll = &H1F0000
  18. Public Const conReadControl = &H20000
  19. Public Const conStandardRightsRead = (conReadControl)
  20. Public Const conRegSz = 1
  21. Public Const conOK = 0&
  22. Public Const conKeyQueryValue = &H1
  23. Public Const conKeySetValue = &H2
  24. Public Const conKeyCreateLink = &H20
  25. Public Const conKeyCreateSubKey = &H4
  26. Public Const conKeyEnumerateSubKeys = &H8
  27. Public Const conKeyNotify = &H10
  28. Public Const conSynchronise = &H100000
  29. Public Const conRegOptionNonVolatile = 0
  30. Public Const conKeyAllAccess = ((conStandardRightsAll _
  31.                               Or conKeyQueryValue _
  32.                               Or conKeyCreateSubKey _
  33.                               Or conKeyEnumerateSubKeys _
  34.                               Or conKeyNotify _
  35.                               Or conKeyCreateLink) _
  36.                             And (Not conSynchronise))
  37. Public Const conKeyRead = ((conReadControl _
  38.                          Or conKeyQueryValue _
  39.                          Or conKeyEnumerateSubKeys _
  40.                          Or conKeyNotify) _
  41.                        And (Not conSynchronise))
  42.  
  43. Private Const conUseShowWindow = &H1&
  44. Private Const conNormalPriority = &H20&
  45. Private Const conInfinite = -1&
  46. Private Const conWinVis = &H10000000
  47. Private Const conGWLStyle = -16
  48.  
  49. Private Type typStartupInfo
  50.     cbLen As Long
  51.     lpReserved As String
  52.     lpDesktop As String
  53.     lpTitle As String
  54.     dwX As Long
  55.     dwY As Long
  56.     dwXSize As Long
  57.     dwYSize As Long
  58.     dwXCount As Long
  59.     dwYCount As Long
  60.     dwFillAtt As Long
  61.     dwFlags As Long
  62.     wShowWindow As Integer
  63.     cbReserved2 As Integer
  64.     lpReserved2 As Long
  65.     hStdIn As Long
  66.     hStdOut As Long
  67.     hStdErr As Long
  68. End Type
  69.  
  70. Private Type typProcInfo
  71.     hProc As Long
  72.     hThread As Long
  73.     dwProcID As Long
  74.     dwThreadID As Long
  75. End Type
  76.  
  77. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
  78.     Alias "RegOpenKeyExA" (ByVal hKey As Long, _
  79.                            ByVal lpSubKey As String, _
  80.                            ByVal ulOptions As Long, _
  81.                            ByVal samDesired As Long, _
  82.                            phkResult As Long) As Long
  83. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
  84.                              As Long
  85. Private Declare Function RegQueryValueExStr Lib "advapi32.dll" _
  86.     Alias "RegQueryValueExA" (ByVal hKey As Long, _
  87.                               ByVal lpValueName As String, _
  88.                               ByVal lpReserved As Long, _
  89.                               lpType As Long, _
  90.                               ByVal lpData As String, _
  91.                               lpcbData As Long) As Long
  92.  
  93. Private Declare Function CreateProcessA Lib "kernel32" ( _
  94.     ByVal lpApplicationName As Long, _
  95.     ByVal lpCommandLine As String, _
  96.     ByVal lpProcessAttributes As Long, _
  97.     ByVal lpThreadAttributes As Long, _
  98.     ByVal bInheritHandles As Long, _
  99.     ByVal dwCreationFlags As Long, _
  100.     ByVal lpEnvironment As Long, _
  101.     ByVal lpCurrentDirectory As Long, _
  102.     lpStartupInfo As typStartupInfo, _
  103.     lpProcessInformation As typProcInfo) As Long
  104. Private Declare Function WaitForSingleObject Lib "kernel32" ( _
  105.     ByVal hHandle As Long, _
  106.     ByVal dwMilliseconds As Long) As Long
  107. Private Declare Function CloseHandle Lib "kernel32" ( _
  108.     ByVal hObject As Long) As Long
  109.  
  110. Private Declare Function FindWindowEx Lib "user32" _
  111.     Alias "FindWindowExA" (ByVal hwndParent As Long, _
  112.                            ByVal hwndChildAfter As Long, _
  113.                            ByVal lpszClass As String, _
  114.                            ByVal lpszWindow As String) As Long
  115. Private Declare Function GetWindowLong Lib "user32" _
  116.     Alias "GetWindowLongA" (ByVal hwndID As Long, _
  117.                             ByVal nIndex As Long) As Long
  118.  
  119. Public Function RegRead(ByVal lngHive As Long, _
  120.                         ByVal strKey As String, _
  121.                         ByVal strValue As String) As Variant
  122.     Dim intIdx As Integer, intHK As Integer
  123.     Dim strWork As String
  124.     Dim lngRet As Long, cbLen As Long, lngHKey As Long, lngType As Long
  125.  
  126.     RegRead = Null
  127.     strKey = strKey & Chr(0)
  128.     lngRet = RegOpenKeyEx(lngHive, strKey, 0, conKeyRead, lngHKey)
  129.     If lngRet = conOK Then
  130.         'Create buffer to store value
  131.         strWork = Space(255)
  132.         cbLen = 255
  133.         lngRet = RegQueryValueExStr(lngHKey, _
  134.                                     strValue, _
  135.                                     0&, _
  136.                                     lngType, _
  137.                                     strWork, _
  138.                                     cbLen)
  139.         RegRead = Left(strWork, cbLen - 1)
  140.         If Len(RegRead) = 254 Then RegRead = Null
  141.         'Close key
  142.         Call RegCloseKey(lngHKey)
  143.     End If
  144. End Function
  145.  
  146. 'ShellWait() executes a command synchronously (Shell() works asynchronously).
  147. Public Sub ShellWait(strCommand As String, _
  148.                      Optional intWinStyle As Integer = vbNormalFocus)
  149.     Dim objProcInfo As typProcInfo
  150.     Dim objStart As typStartupInfo
  151.     Dim lngRet As Long
  152.  
  153.     'Initialize the typStartupInfo structure:
  154.     With objStart
  155.         .cbLen = Len(objStart)
  156.         .dwFlags = conUseShowWindow
  157.         .wShowWindow = intWinStyle
  158.     End With
  159.     'Start the shelled application:
  160.     Call CreateProcessA(lpApplicationName:=0&, _
  161.                         lpCommandLine:=strCommand, _
  162.                         lpProcessAttributes:=0&, _
  163.                         lpThreadAttributes:=0&, _
  164.                         bInheritHandles:=1&, _
  165.                         dwCreationFlags:=conNormalPriority, _
  166.                         lpEnvironment:=0&, _
  167.                         lpCurrentDirectory:=0&, _
  168.                         lpStartupInfo:=objStart, _
  169.                         lpProcessInformation:=objProcInfo)
  170.     'Wait for the shelled application to finish
  171.     Call WaitForSingleObject(hHandle:=objProcInfo.hProc, _
  172.                              dwMilliseconds:=conInfinite)
  173.     Call CloseHandle(hObject:=objProcInfo.hProc)
  174. End Sub
  175.  
  176. Public Function DBWindowVisible() As Boolean
  177.     Dim hWnd As Long, lngStyle As Long
  178.  
  179.     'Get handle of MDIClient window of current application
  180.     hWnd = FindWindowEx(hWndAccessApp, 0, "MDIClient", vbNullString)
  181.     'Within that, find child window matching class Odb (database window)
  182.     hWnd = FindWindowEx(hWnd, 0, "Odb", vbNullString)
  183.     'Default result to False in case handle wasn't found
  184.     DBWindowVisible = False
  185.     If (hWnd) Then
  186.         'Having found window, check the visibility flag of its style value
  187.         lngStyle = GetWindowLong(hWnd, conGWLStyle)
  188.         DBWindowVisible = ((lngStyle And conWinVis) = conWinVis)
  189.     End If
  190. End Function
Feb 17 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.