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

different initial form in MS-ACCESS according to the username 2

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
I don't know if possible but still...
I'd like,for different forms to be opened first, depending on the username.
For example: When I open a certain MS ACCESS database, I'd like a certain form to be opened automaticaly, and when other user opens that database, that another initial form will be opened. The different forms already exist.
We use Novell for login the computers. Can the initial form be opened, according to the Novell username of the user?

Actually, I need only 2 different forms.
The purpose: When I use the database, I want to see a main page with menu as the initial form, so I can use it, for management.
When other users open the database, I want them to see a certain form as the initial form. They can edit stuff, change things, designs etc. And that's ok.

Any idea?
 
I have a class module that will help you get the job done. why don't email me and I will forward the access modules to you? vickvickvi@hotmail.com what you are asking for is the code that will get you the user name from the log in information so you do not have to use the access security. Forget it. I pasted the class module in the email.

GOOD Luck to you.
Michael Vick

Here is the module that I believe will do what you are asking for:

Mycomputer: Class Module
Option Compare Database
Option Explicit

'*************************************************************************
'* INTERFACE *
'*************************************************************************

'Public collections
Public Drives As New Collection


'*************************************************************************
'* IMPLEMENTATION *
'*************************************************************************

'Windows structure declarations
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End Type


Private Type OSVERSION_INFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Private Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

'Windows API function declarations
Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSION_INFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
(ByVal sBuffer As String, lSize As Long) As Long
Private Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA" _
(ByVal sBuffer As String, lSize As Long) As Long
Private Declare Function timeGetTime Lib "winmm" () As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, rectangle As RECT) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long


'Windows constant declarations
Private Const SM_SWAPBUTTON = 23
Private Const PROCESSOR_INTEL_386 = 386
Private Const PROCESSOR_INTEL_486 = 486
Private Const PROCESSOR_INTEL_PENTIUM = 586
Private Const PROCESSOR_MIPS_R4000 = 4000
Private Const PROCESSOR_ALPHA_21064 = 21064
Private Const PROCESSOR_ARCHITECTURE_INTEL = 0
Private Const PROCESSOR_ARCHITECTURE_MIPS = 1
Private Const PROCESSOR_ARCHITECTURE_ALPHA = 2
Private Const PROCESSOR_ARCHITECTURE_PPC = 3
Private Const PROCESSOR_ARCHITECTURE_UNKNOWN = &HFFFF
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

'Private variable declarations
Private strAccessDir As String
Private strComputerName As String
Private strUserName As String
Private typSysInfo As SYSTEM_INFO
Private typOSVersion As OSVERSION_INFO
Private lngMemoryInstalled As Long
Private lngID As Long

Private Sub Class_Initialize()
'*****************************************************************************
'* NAME: CLASS_INITIALIZE
'* PURPOSE: To initialize variables when MyComputer object is instantiated
'* ACCEPTS: Nothing
'* RETURNS: Nothing
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: This procedure also populates the Disks collection
'*****************************************************************************

Dim strDriveString As String
Dim intDriveLength As Integer
Dim strDrive() As String
Dim intDriveCount As Integer
Dim intPos As Integer
Dim intcounter As Integer
Dim lngBuffSize As Long
Dim typDrive As Drive

'Get OS version information
typOSVersion.dwOSVersionInfoSize = Len(typOSVersion)
GetVersionEx typOSVersion

'Get system information (e.g. processor type)
GetSystemInfo typSysInfo

'Get Access directory
strAccessDir = SysCmd(acSysCmdAccessDir)

'Get computer name
strComputerName = Space$(255)
lngBuffSize = Len(strComputerName)
If GetComputerName(strComputerName, lngBuffSize) Then
strComputerName = Left$(strComputerName, lngBuffSize)
End If

'Get user name
strUserName = Space$(255)
lngBuffSize = Len(strUserName)
If GetUserName(strUserName, lngBuffSize) Then
strUserName = Left$(strUserName, lngBuffSize - 1)
End If

'Get details of drives
strDriveString = Space$(255)
lngBuffSize = Len(strDriveString)
intDriveLength = GetLogicalDriveStrings(lngBuffSize, strDriveString)
intPos = InStr(1, strDriveString, "\")

Do While intPos <> 0
ReDim Preserve strDrive(intDriveCount)
strDrive(intDriveCount) = Mid$(strDriveString, intPos - 2, 3)
intDriveCount = intDriveCount + 1
intPos = InStr(intPos + 1, strDriveString, &quot;\&quot;)
Loop

For intcounter = 0 To intDriveCount - 1
Set typDrive = New Drive
typDrive.Root = strDrive(intcounter)
Drives.Add typDrive
Set typDrive = Nothing
Next

lngID = timeGetTime

End Sub

Public Property Get AccessDir() As String
'*****************************************************************************
'* NAME: ACCESSDIR
'* PURPOSE: To allow the AccessDir property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the directory in which Access is installed
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

AccessDir = strAccessDir

End Property

Public Property Get ButtonsSwapped() As Boolean
'*****************************************************************************
'* NAME: BUTTONSSWAPPED
'* PURPOSE: To allow the ButtonsSwapped property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: False if the mouse is configured for left-handed use
'* True (non-zero) otherwise
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

ButtonsSwapped = GetSystemMetrics(SM_SWAPBUTTON)

End Property

Public Property Let ButtonsSwapped(bSwap As Boolean)
'*****************************************************************************
'* NAME: BUTTONSSWAPPED
'* PURPOSE: To allow the ButtonsSwapped property to be set
'* ACCEPTS: True (non-zero) if the mouse is to be configured for left-handed use
' False if the mouse is to be configured for (default) right-handed use
'* RETURNS: Nothing
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

Dim lngSwap As Long

lngSwap = CLng(bSwap)
Call SwapMouseButton(lngSwap)

End Property

Public Sub SwapButtons(bSwap As Boolean)
'*****************************************************************************
'* NAME: SWAPBUTTONS
'* PURPOSE: To expose the SwapButtons method
'* ACCEPTS: True (non-zero) if the mouse is to be configured for left-handed use
' False if the mouse is to be configured for (default) right-handed use
'* RETURNS: Nothing
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: This provides identical functionality to the ButtonsSwapped property
'*****************************************************************************

SwapMouseButton bSwap

End Sub

Public Function SwapButtonCheck(bSwap As Boolean) As Boolean
'*****************************************************************************
'* NAME: SWAPBUTTONCHECK
'* PURPOSE: To allow the ButtonsSwapped property to be set and determine whether
'* this results in a changed mouse configuration
'* ACCEPTS: True (non-zero) if the mouse is to be configured for left-handed use
' False if the mouse is to be configured for (default) right-handed use
'* RETURNS: True if the mouse configuration changes as a result of this call;
'* False otherwise
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

Dim bNewState As Boolean

bNewState = SwapMouseButton(bSwap)
If bNewState = bSwap Then
SwapButtonCheck = False
Else
SwapButtonCheck = True
End If

End Function

Public Property Get CPUArchitecture() As String
'*****************************************************************************
'* NAME: CPUARCHITECTURE
'* PURPOSE: To allow the CPUArchitecture property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the type of processor installed
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: FOr Win95, this will always be &quot;Intel&quot;
'*****************************************************************************

Select Case typSysInfo.dwOemID
Case PROCESSOR_ARCHITECTURE_INTEL
CPUArchitecture = &quot;Intel&quot;
Case PROCESSOR_ARCHITECTURE_MIPS
CPUArchitecture = &quot;MIPS&quot;
Case PROCESSOR_ARCHITECTURE_ALPHA
CPUArchitecture = &quot;Alpha&quot;
Case PROCESSOR_ARCHITECTURE_PPC
CPUArchitecture = &quot;PowerPC&quot;
Case PROCESSOR_ARCHITECTURE_UNKNOWN
CPUArchitecture = &quot;Unknown&quot;
End Select

End Property

Public Property Get OSName() As String
'*****************************************************************************
'* NAME: OSNAME
'* PURPOSE: To allow the OSName property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the name of the operating system installed
'* e.g. Windows NT 4.0 Build 1381
'* ~~~~~~~~~~
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: Further information is in the OSVersion and OSBuild properties
'*****************************************************************************

Select Case typOSVersion.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
OSName = &quot;Windows 95&quot;
Case VER_PLATFORM_WIN32_NT
OSName = &quot;Windows NT&quot;
End Select

End Property

Public Property Get OSVersion() As String
'*****************************************************************************
'* NAME: OSVERSION
'* PURPOSE: To allow the OSVersion property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the version of the operating system installed
'* e.g. Windows NT 4.0 Build 1381
'* ~~~
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: Further information is in the OSVersion and OSBuild properties
'*****************************************************************************

OSVersion = typOSVersion.dwMajorVersion & &quot;.&quot; & typOSVersion.dwMinorVersion

End Property

Public Property Get OSBuild() As String
'*****************************************************************************
'* NAME: OSBUILD
'* PURPOSE: To allow the OSBuild property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the build of the operating system installed
'* e.g. Windows NT 4.0 Build 1381
'* ~~~~
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: Further information is in the OSVersion and OSBuild properties
'*****************************************************************************

OSBuild = typOSVersion.dwBuildNumber And &HFFFF&

End Property

Public Property Get CPULevel() As String
'*****************************************************************************
'* NAME: CPULEVEL
'* PURPOSE: To allow the CPULevel property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the level of CPU installed
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: If the operating system is Win95, this value is found in the
' dwProcessorType element returned by GetSystemInfo. If WinNT,
' the value is in the wProcessorLevel element, and values returned
' are dependent on processor architecture
'*****************************************************************************

Select Case typOSVersion.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
Select Case typSysInfo.dwProcessorType
Case PROCESSOR_INTEL_386
CPULevel = &quot;386&quot;
Case PROCESSOR_INTEL_486
CPULevel = &quot;486&quot;
Case PROCESSOR_INTEL_PENTIUM
CPULevel = &quot;Pentium&quot;
End Select
Case VER_PLATFORM_WIN32_NT
Select Case typSysInfo.dwOemID
Case PROCESSOR_ARCHITECTURE_INTEL
Select Case typSysInfo.wProcessorLevel
Case 3
CPULevel = &quot;386&quot;
Case 4
CPULevel = &quot;486&quot;
Case 5
CPULevel = &quot;Pentium&quot;
End Select
Case PROCESSOR_ARCHITECTURE_MIPS
Select Case typSysInfo.wProcessorLevel
Case 4
CPULevel = &quot;R4000&quot;
End Select
Case PROCESSOR_ARCHITECTURE_ALPHA
Select Case typSysInfo.wProcessorLevel
Case 21064
CPULevel = &quot;21064&quot;
Case 21066
CPULevel = &quot;21066&quot;
Case 21164
CPULevel = &quot;21164&quot;
End Select
Case PROCESSOR_ARCHITECTURE_PPC
Select Case typSysInfo.wProcessorLevel
Case 1
CPULevel = &quot;601&quot;
Case 3
CPULevel = &quot;603&quot;
Case 4
CPULevel = &quot;604&quot;
Case 6
CPULevel = &quot;603+&quot;
Case 9
CPULevel = &quot;604+&quot;
Case 20
CPULevel = &quot;620&quot;
End Select
Case PROCESSOR_ARCHITECTURE_UNKNOWN
CPULevel = &quot;Unknown&quot;
End Select
End Select

End Property

Public Property Get ComputerName() As String
'*****************************************************************************
'* NAME: COMPUTERNAME
'* PURPOSE: To allow the ComputerName property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the name of the computer
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

ComputerName = strComputerName

End Property

Public Property Get UserName() As String
'*****************************************************************************
'* NAME: USERNAME
'* PURPOSE: To allow the UserName property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the name of the currently logged-on user
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

UserName = strUserName

End Property

Public Property Get WinStarted() As Date
'*****************************************************************************
'* NAME: WINSTARTED
'* PURPOSE: To allow the WinStarted property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A date indicating when Windows was last started
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES: This value will not be accurate once the threshold of timeGetTime
' has been exceeded (around 47 days)
'*****************************************************************************

WinStarted = DateAdd(&quot;s&quot;, timeGetTime() / -1000, Now)

End Property

Public Property Get ScreenResolution() As String
'*****************************************************************************
'* NAME: SCREENRESOLUTION
'* PURPOSE: To allow the ScreenResolution property to be inspected
'* ACCEPTS: Nothing
'* RETURNS: A string indicating the current screen resolution (e.g. 640x480)
'* AUTHOR: Rob Smith
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

Dim rct As RECT
Dim hwnd As Long
Dim lngReturn As Long

hwnd = GetDesktopWindow()
lngReturn = GetWindowRect(hwnd, rct)

ScreenResolution = (rct.x2 - rct.x1) & &quot;x&quot; & (rct.y2 - rct.y1)


End Property

Public Property Get ID() As Long
'*****************************************************************************
'* NAME: ID
'* PURPOSE: To return the unique ID of this class instance
'* ACCEPTS: Nothing
'* RETURNS: A long representing a unique(-ish?) ID
'* AUTHOR: David Sussman
'* DATE: 22/06/97
'* NOTES:
'*****************************************************************************

ID = lngID

End Property

 

vickvickvi,

WoW. A ton of 'stuff'. I am not sure that the answer is in there, although at least part of it is. From long away and far ago, (Win 3.1?) You could get the Novell UserName with just a simple service call from Ms. Access. But the QUESTION was to INITALLY open a different form depending on the UserName.

I do not believe this can be done, as Access always has a startup form which is loaded as the initial form (without a DECLARED startup form, it defaults to the database window). You CAN, however, create what is commonly known as a 'Splash Screen&quot;, this is usually the title and credits (ego stuff) abouthte app and its creators. Having this be the startup form and processing 'stuff' like the username could THEN be used to open the subsquent form - according to the UserName.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
vickvickvi, thanks. It's too heavy for me, and I can't really follow what's going on there.
MichaelRed,How can I &quot;get the Novell UserName with just a simple service call from Ms. Access&quot;?
Suppose I have a splash screen, what do I do then? How can I open the right form according to the username then???

Thanks
 
Getting the Novell UserName escapes me. It has been WAY to long for an old man's memory. Setting the next Screen (Form) after you get the UserName is 'trivial'.


If (UserName = &quot;Michael Red&quot;) then
[tab] DoCmd.OpenForm &quot;MyForm&quot;
Else
[tab]doCmd.OpenForm &quot;Their Form&quot;
End If

You also need to close the splash screen.

Try the Novell Forum ? for info on gettign the network user name.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Here is one solution you can try.

If there is any startup form, take it out.
Instead create an Autoexec macro and run the following code substituting your user and form names;

---------------------------------------------------------
Option Compare Database
Option Explicit
Private Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias &quot;GetUserNameA&quot; (ByVal lpbuffer As String, nSize As Long) As Long

Function Startup_Form()
Dim sBuffer As String
Dim gUser As Variant
Dim lSize As Long

sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)

gUser = Left$(sBuffer, lSize)
If gUser = &quot;user1&quot; Then
DoCmd.OpenForm &quot;frmUser1&quot;
ElseIf gUser = &quot;user2&quot; Then
DoCmd.OpenForm &quot;frmUser2&quot;
Else
DoCmd.OpenForm &quot;frmOtherUsers&quot;
End If
End Function

Jim.
 
Looks simple and good, but does the &quot;advapi32.dll&quot; file recognize the kind of loggins that are made? I mean, does it recognize if it's Novell or windows login?
I need it to work for Novell only.

Btw - I know nothing about dll. How can I view it's source code? Notepad does not let me view an executable file.

Thanks


 
This file recognizes both Windows and Novell login I'm afraid, this is the extent of my knowledge on .dll files also.
There may be a file which would pick out the Novell login only, I would reiterate MichaelRed's advice to try the Novell Forum for more info.

Jim.
 
The API declaration (of the dll file) is what I refered to as a 'Service Call'. It is probably an updated version of the same thing I used long away and far ago. &quot;.dll&quot; files are executable code which you cannot 'read' in a text editor. The 'dll' stands for &quot;Dynamic Link Library&quot; and is the common mechanisim for using pre-compiled code. MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
I will ask that thanks both for your help.
 
Thanks Michael for the explanation.
Jim, I just used your code and it works great, using Novell.
Thanks

Btw - I wonder, what happens when Novell is not working for some reason, and there are no network resources?
What value will the &quot;gUser&quot; return, and how will that effect the initial form in the database?
Moreover, if it does cause problem, how do I prevent from error msg to appear in this case?
------------Solution -----------------
Now, in case anyone wonders how to use your code:
I created a macro named autoExec, and chose the &quot;runCode&quot; there, and filled in the name of the function: &quot;Startup_Form()&quot;.
Then' I copied your code above (changed names, etc.), to a new module.
End of story.

Jim, Thank you very much for making it so simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top