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!

Startup Form Depends on User 1

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
US
I'm working with an Access 2000 database. I have two forms named frmMonToSat and frmSunday. My company has one group of employees who work with this db Monday - Saturday, and another group who work with it on Sundays.

I need frmMonToSat to be the startup form when the database is used between Monday and Saturday, and I need to have frmSunday be the startup form when the database is used Sunday. Is this possible?

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Have an indicator on the employee record that will identify the group the user belongs to. When the user logs in, I assume there is a log in procedure, lookup the indicator, run it through a select case statement and open the appropriate form based on the indicator

'At the point where you open the form in your log in procedure add something like the following:

Dlookup("[indicator]", "tblEmployee", "[EmpLoginID]" = '" & loginid & "'")

Select case "Group"
Case "A"
docmd.openform "FormA"
Case "B"
docmd.openform "FormB"
End Select

This is just a kneejerk response, let me know if you need more details.

Mike
 
Mike, Thanks for this great information. I'm not sure where I would place this code, though, because my users do not actually log into the database. Everyone just opens it up and begins using it. Where would you suggest I place this code? Thanks!

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
You should have some kind of log in procedure (since the DB can't tell who is logging in without it. The code below isn't perfect as it is just off the top of my head but it'll give you a direction to go in. Let me know how it works out.

Minimum: Create a table that contains info about the employees with a log in name of some sort. Don't worry about passwords, you can always add that stuff later.

tblEmployee:
last_name
first_name
login_id "this could be first initial & last name"
form_name

You will next need a form to log in to:
Create a new form with a field for the user to enter their login id and an enter button

When the user logs on and clicks enter, do the following:
1)Check to see if they are a user listed on the table
2)If not throw up a message box telling them who to contact to see about getting access.
3)If they are in the database, run the select case and open the appropriate form. You could actually store the form name in the tblEmployee table to make the code a little cleaner.
4)Close the log in form

Call the custom function when you click enter on the log in form

function customfunction()
If IsNull(Dlookup("[login_id]", "tblEmployee", "[EmpLoginID]" = '" & Forms!frmLogIn![loginid] & "'")) Then
MsgBox("Contact Joe Schmoe for access")
docmd.quit
else
docmd.openform Dlookup("[form_name]", "tblEmployee", "[EmpLoginID]" = '" & Forms!frmLogIn![loginid] & "'"))
docmd.close Forms!frmLogIn
end if
end function
 
you could run an if statement based on the DateTime.Day procedure.

ie have a blank form as your startup form and the if statment in it, if datetime.day = Sunday then open the relevent form.

nb dont know if date time uses the days name or the days number, ie sunday = day 7
 
Mike (Page410),

Excellent post. I've been trying to think of a method of doing something almost identical.

I'd like to draw information from the standard access security and use that to decide what forms are opened.

Hope you don't mind - I've posted a fresh question on it.

Thanks,
Owen
 
Just a note: if the users are logging in with different windows IDs then you could simply "grab" that and use them to determine what form is opened. =environ("username")
 
Good point about the environ call MinnKota.

However, show some caution when using it as it is dependant on the O/S. I think the environ("username") worked OK for me in Win95/98 however I got stung in Win 2000 and had to use environ("nwusername").

Failing that of course you could use an API call:

Place this in the general declerations of a module:

Code:
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
     (ByVal lpBuffer As String, nSize As Long) As Long

And make the call using

Code:
        Dim lpBuff As String * 25
        Dim ret As Long
        Dim UserName As String

        ret = GetUserName(lpBuff, 25)
        UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
        MsgBox = UserName

Hope you find this helpful.

John
 
Check out this Faq:

faq705-2814

Get user name from Windows 2000
faq705-2814

If not already done so, create a new module in the Modules section.

Paste this statement into the General Declarations section of the module:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Paste this code:

Function fWin2KUserName() As String
Dim lngLength As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLength = 255
lngX = apiGetUserName(strUserName, lngLength)
If lngX <> 0 Then
fWin2KUserName = Left$(strUserName, lngLength - 1)
Else
fWin2KUserName = "unknown"
End If
End Function

You can run this function (fWin2KUserName) from anywhere within your application. The best way is to set some variable to be equal to the function:
Dim strUser as String
strUser = fWin2KUserName

 
Of course retrieving the network login assumes that a user will only access the system from his or her own workstation or that they will log in to the network from another users machine.
 
Yo Mike! (You still out there?)

As often happens, your thread has attracted OIP - Other Interested Parties.

It sounds like you have a basic database without heavy security, etc. It also sounds like you don't care who the User is, only that he/she is working Mon-Sat or on Sun.
Stop me if I'm wrong...

What you could do is create a new startup (splash?) form and trigger it in Startup. You don't really need anything in the form, you just need it as the database's starting point.

Create an Onload event for that form - let's call it frmSplash. The Onload event code would look something like this:

Code:
Private Sub Form_Load()
DoCmd.Minimize   'HIDE THE OPENING FORM
If Weekday(Date()) = vbSunday then
    DoCmd.Openform "frmSunday"
Else
    DoCmd.Openform "frmMonToSat"
End If
End Sub

This is rudimentary, and it leaves frmSplash open.
But it might be all you're looking for at this time.



HTH,
Bob [morning]
 
I appologize for not responding - I've been on vacation.

Thank you all for the posts. cranebill, I've already implemented the exact method you've described and it works perfectly.

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
CrainBill,

Am currently developing a medium sized database client- server app that I have been planning to use a Windows Login as userID. Used your code and it is like greased lightning. Thanks for all your help.


just another grateful admirer.
[smile2]


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top