![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
All, I have a formless db with a table containing a myLoginID column. I would like to use the currently logged-in user's ID as the default value for said column when my (outside) VB app writes a record to the DB. I would like to avoid doing this in VB code if possible. I understand Access did not used to support the use of a custom function a Default Value - is that still true? If so, is there another way to do this? If not, what am I doing wrong? My function code is below. I can't save the table when I use UserName() as the default. Thanks, Patrick Function UserName() 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 UserName = Left$(strUserName, lngLen - 1) Else UserName = vbNullString End If End Function If not, |
#3
| |||
| |||
|
|
Patrick A wrote: All, I have a formless db with a table containing a myLoginID column. I would like to use the currently logged-in user's ID as the default value for said column when my (outside) VB app writes a record to the DB. I would like to avoid doing this in VB code if possible. I understand Access did not used to support the use of a custom function a Default Value - is that still true? If so, is there another way to do this? If not, what am I doing wrong? *My function code is below. I can't save the table when I use UserName() as the default. Thanks, Patrick * * Function UserName() 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 * * * * * * UserName = Left$(strUserName, lngLen - 1) * * * * Else * * * * * * UserName = vbNullString * * * * End If * * End Function If not, I created a code module and entered the following BEFORE the function, at the top of the code module. *Did you compile your app? Option Compare Database Option Explicit Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ * * *"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Seehttp://www.mvps.org/access/api/api0008.htm- Hide quoted text - - Show quoted text - |
#4
| |||
| |||
|
|
Salad, Thanks, yes, I did. The function returns the username to a Query, I just can't get it to return the username as a default in a table. |
#5
| |||
| |||
|
|
Patrick A wrote: Salad, Thanks, yes, I did. *The function returns the username to a Query, I just can't get it to return the username as *a default in a table. Is there a need to set the default value using a UDF in the table? *If you can't use a form, use a query. Create Table1 Create Query1 (Select F1, F2, GetUserName() AS UserN From *Table1) Use Query1 for input or as recordsource for forms/reports. Use Query1. *You can't use UDFs as the default values of a table. |
![]() |
| Thread Tools | |
| Display Modes | |
| |