i am designing a form in access that will be run by an autoexec macro, i have minimal experience in access and have only recently started form design in it in any detail.
The objective of the form is to hold a login screen for a data source database. I have done this many times in normal vb and it work fine.
However the code will not pick up the user name as it normally does. the code is below any ideas.
it is also saying: i cant reference a control unless the control has the focus.
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
txt_username.Text = Left$(sBuffer, lSize)
Else
txt_username.Text = vbNullString
End If
End Sub
The objective of the form is to hold a login screen for a data source database. I have done this many times in normal vb and it work fine.
However the code will not pick up the user name as it normally does. the code is below any ideas.
it is also saying: i cant reference a control unless the control has the focus.
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
txt_username.Text = Left$(sBuffer, lSize)
Else
txt_username.Text = vbNullString
End If
End Sub