Private Sub Form_Open(Cancel As Integer)
'This is the registration form's OnOpen event
'Everyone should have a user type (UType) '1', and admins also have a 2,3,4,5 or 6
Select Case DCount("UType", "tblPPL", "UName = '" & fOSUserName() & "'")
Case Is = 0
'user not loaded yet...allow form to open and register...
CopyDB (False) 'copy the standard user's front end
MsgBox "The application has been set up on your computer." & vbCrLf & _
"Use the 'FitDB' shortcut on your Desktop to access the program." & vbCrLf & _
"You still need to create a user profile..." & vbCrLf & _
"Complete the entries on the following form."
Me.DataEntry = True
Exit Sub
Case Is = 1
'one entry for this person, check to make sure the UType...
If DLookup("Utype", "tblPPL", "UName = '" & fOSUserName() & "'") > 1 Then
CopyDB (True) 'copy the admin front end
MsgBox "The application has been set up on your computer." & vbCrLf & _
"Use the 'FitDB' shortcut on your Desktop to access the program."
Me.DataEntry = True
Me.Rnk = DLookup("Rnk", "tblPPL", "UName = '" & fOSUserName() & "'")
Me.LName = DLookup("LName", "tblPPL", "UName = '" & fOSUserName() & "'")
Me.FName = DLookup("FName", "tblPPL", "UName = '" & fOSUserName() & "'")
Me.FltID = DLookup("FltID", "tblPPL", "UName = '" & fOSUserName() & "'")
'the default for user type is '1'
DoCmd.RunCommand acCmdSaveRecord
Application.Quit
Else
CopyDB (False)
MsgBox "You have updated the application on your computer." & vbCrLf & _
"Continue to run the application from your desktop shortcut."
End If
Case Is > 1
'person has higher access...
CopyDB (True)
MsgBox "You have updated the application on your computer." & vbCrLf & _
"Continue to run the application from your desktop shortcut."
Cancel = True
Application.Quit
Case Else
MsgBox "An error has occurred...contact the database administrator"
End Select
Cancel = True
Application.Quit
End Sub
Function fOSUserName() As String
'Returns the network login name (function found on this forum)
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
ElsefOSUserName = ""
End If
End Function
Public Sub CopyDB(Optional LoadAdmin As Boolean = False)
Dim fso As New FileSystemObject
Dim UProf As String
Dim DBLoc As String
Dim objShell
Dim objShortcut
'Check to see if they have the FitDB folder in "MyDocs"...
UProf = Environ("userprofile")
If Not fso.FolderExists(UProf & "\My Documents\FitDB") Then
fso.CreateFolder UProf & "\My Documents\FitDB"
End If
If LoadAdmin Then
'Select Admin DB...
DBLoc = CurrentProject.Path & "\BackEnd\FitnessAdmin.mdb"
Else
DBLoc = CurrentProject.Path & "\BackEnd\Fitness.mdb"
End If
fso.CopyFile DBLoc, UProf & "\My Documents\FitDB\Fitness.mdb"
fso.CopyFile CurrentProject.Path & _
"\BackEnd\jogger.ico", "C:\WINDOWS\system32\jogger.ico"
Set objShell = New WshShell
Set objShortcut = objShell.CreateShortcut(UProf & "\Desktop\FitDB.lnk")
objShortcut.TargetPath = UProf & "\My Documents\FitDB\Fitness.mdb"
objShortcut.IconLocation = "%SystemRoot%\system32\jogger.ico"
objShortcut.Save
Set objShell = Nothing
Set objShortcut = Nothing
End Sub