B
BDPIII
I have a module with the code below, the function works fine when ran in the
Immediate window but when I set the default value of a textbox on a field to
the function "=GetUser()" it is not returning anything in the text box.
Option Compare Database
Type WKSTA_USER_INFO_1
wkui1_username As Long
End Type
Declare Function WNetGetUser& Lib "Mpr" Alias "WNetGetUserA" _
(lpName As Any, ByVal lpUserName$, lpnLength&)
Function GetUser()
Dim ret As Long, buffer(512) As Byte, i As Integer
Dim cbusername As Long, username As String
' Windows 95 or NT - call WNetGetUser to get the name of the user.
username = Space(256)
cbusername = Len(username)
ret = WNetGetUser(ByVal 0&, username, cbusername)
If ret = 0 Then
' Success - strip off the null.
username = Left(username, InStr(username, Chr(0)) - 1)
Else
username = ""
End If
Debug.Print username
End Function
I have also tried to change another field's after update property to set the
username field to
Private Sub ordernumber_AfterUpdate()
If Me![ordernumber] > 0 Then
Me![username] = GetUser()
End If
End Sub
When I do this I get a runtime error which says username cannot be a zero
length string. I can go back to my VBA screen and see that the function has
run in the immediate widow successfully.
Thanks in advance for any help!
Barry
Immediate window but when I set the default value of a textbox on a field to
the function "=GetUser()" it is not returning anything in the text box.
Option Compare Database
Type WKSTA_USER_INFO_1
wkui1_username As Long
End Type
Declare Function WNetGetUser& Lib "Mpr" Alias "WNetGetUserA" _
(lpName As Any, ByVal lpUserName$, lpnLength&)
Function GetUser()
Dim ret As Long, buffer(512) As Byte, i As Integer
Dim cbusername As Long, username As String
' Windows 95 or NT - call WNetGetUser to get the name of the user.
username = Space(256)
cbusername = Len(username)
ret = WNetGetUser(ByVal 0&, username, cbusername)
If ret = 0 Then
' Success - strip off the null.
username = Left(username, InStr(username, Chr(0)) - 1)
Else
username = ""
End If
Debug.Print username
End Function
I have also tried to change another field's after update property to set the
username field to
Private Sub ordernumber_AfterUpdate()
If Me![ordernumber] > 0 Then
Me![username] = GetUser()
End If
End Sub
When I do this I get a runtime error which says username cannot be a zero
length string. I can go back to my VBA screen and see that the function has
run in the immediate widow successfully.
Thanks in advance for any help!
Barry