log in form

buggy2

Board Regular
Joined
Feb 28, 2003
Messages
69
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
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
fix

well putting it on paper opened my eyes. all i needed to do was to set the focus on the username text box.

txt_username.setfocus
 
Upvote 0

Forum statistics

Threads
1,221,513
Messages
6,160,242
Members
451,632
Latest member
purpleflower26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top