cclark9589
Registered User.
- Local time
- , 17:11
- Joined
- Sep 22, 2008
- Messages
- 79
Time and Billing db using Access 2007
I'm trying to filter the time card form using fosusername() so that time cards for the logged in user are the only one's visible. I'm stuck because I don't know squat.
I created tblUserNames: UserID (pk), UserName, NetName, & AudID. NetName is the network username and AudID is the pk from tblEmployees and the fk on the Time Card form. I created a Login form with one text box with =fOSUserName() as the control source and one button that opens the switchboard. When the button is clicked, Login form is minimized. I got the idea of this from a previous post but can't seem to get it to work. My db opens to Login and it seems to work but after that I am totally lost. In the On Load event I have "Call fOSUserName() in a private sub.
On the Time Card form I have "EmpNameCombo=fOSUserName()" in the Filter property. In form On Load event I have the following code:
Private Sub Form_Load()
'Me.Filter = "[EmpNameCombo]='" & fOSUserName() & "'"
'Me.Filter = "EmpNameCombo = fOSUserName()"
'Me.FilterOn = True
DoCmd.GoToRecord , , acLast
End Sub
The first 3 lines have been remmed out because they haven't worked.
How do I get this to work and where exactly do I place the code?
Not sure if it matters but the Time Card uses 3 sub-forms for entering billable hours, expenses and non-chargeable hours.
Here is the code I have for fOSUserName() in module FindLoginName:
Option Compare Database
Option Explicit
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
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)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************
All help is appreciated, just need it in plain English due to thick skull.
I'm trying to filter the time card form using fosusername() so that time cards for the logged in user are the only one's visible. I'm stuck because I don't know squat.
I created tblUserNames: UserID (pk), UserName, NetName, & AudID. NetName is the network username and AudID is the pk from tblEmployees and the fk on the Time Card form. I created a Login form with one text box with =fOSUserName() as the control source and one button that opens the switchboard. When the button is clicked, Login form is minimized. I got the idea of this from a previous post but can't seem to get it to work. My db opens to Login and it seems to work but after that I am totally lost. In the On Load event I have "Call fOSUserName() in a private sub.
On the Time Card form I have "EmpNameCombo=fOSUserName()" in the Filter property. In form On Load event I have the following code:
Private Sub Form_Load()
'Me.Filter = "[EmpNameCombo]='" & fOSUserName() & "'"
'Me.Filter = "EmpNameCombo = fOSUserName()"
'Me.FilterOn = True
DoCmd.GoToRecord , , acLast
End Sub
The first 3 lines have been remmed out because they haven't worked.
How do I get this to work and where exactly do I place the code?
Not sure if it matters but the Time Card uses 3 sub-forms for entering billable hours, expenses and non-chargeable hours.
Here is the code I have for fOSUserName() in module FindLoginName:
Option Compare Database
Option Explicit
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
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)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************
All help is appreciated, just need it in plain English due to thick skull.