G
Guest
The code below, supplied by Dev Ashish, correctly produces the username from
the fOSUserName() call in the Form_Open event procedure, since the Msgbox()
statement displays the correct user name.
However, instead of filtering the form, it displays a dialog box with the
Heading “Enter Parameter Valueâ€. The username is shown in the “eyebrowâ€,
with the input field blank. If I type the username in, the filter is applied
correctly. If left blank, the form opens to a blank record.
Can someone help me determine how to apply the filter correctly?
Thank you.
Sprinks
'******************* 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 **************************
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Application.Echo False
' Reset Labels & initialize totals
Call ResetLabels
Call UpdateTotals
' Filter By UserName
Me.Filter = "[UserName]= " & fOSUserName()
Me.FilterOn = True
' Move to subform
Me!TimeSheetDetail.SetFocus
Application.Echo True
End Sub
the fOSUserName() call in the Form_Open event procedure, since the Msgbox()
statement displays the correct user name.
However, instead of filtering the form, it displays a dialog box with the
Heading “Enter Parameter Valueâ€. The username is shown in the “eyebrowâ€,
with the input field blank. If I type the username in, the filter is applied
correctly. If left blank, the form opens to a blank record.
Can someone help me determine how to apply the filter correctly?
Thank you.
Sprinks
'******************* 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 **************************
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Application.Echo False
' Reset Labels & initialize totals
Call ResetLabels
Call UpdateTotals
' Filter By UserName
Me.Filter = "[UserName]= " & fOSUserName()
Me.FilterOn = True
' Move to subform
Me!TimeSheetDetail.SetFocus
Application.Echo True
End Sub