Posted on Leave a comment

MSAccess: Launch Form on Startup

I recently had to start doing stuff in MS Access 2007. It has been a great many moons since I’ve worked with Access and, of course, all of the menus have changed.

Now, to get the the settings page for the “Application”, instead of “Options”–>”Tools”, you now click the “Office Button” and down at the bottom of the menu page that pops up is “Access Options”.

This is one location you can specify which form you want to open up automatically when you open the access file.

A nice holdover from previous versions gives another, more flexible method. You can create an macro named “AutoExec” that can launch a macro, form, code module procedure, etc.

To override the default MS Access splash screen, create a 1×1 1bit bitmap file and name it the name as your ms access project (ie: “myproject.bmp”) and place it in the same folder as your ms access project “*.accdb” file.

Posted on Leave a comment

MSAccess: GetNetUser()

If you use “CurrentUser()” you will as often as not get “Admin”, which is the default Access user.

To get the user’s windows authentication login name, place the following code at the top of a standard module:

Private Declare Function WNetGetUserA Lib "mpr.dll" _
(ByVal lpszLocalName As String, ByVal lpszUserName As String, lpcchBuffer As Long) As Long

Public Function GetNetUser() As String
   Dim lpUserName As String, lpnLength As Long, lResult As Long
   'Create a buffer
   lpUserName = String(256, Chr$(0))
   'Get the network user
   lResult = WNetGetUserA(vbNullString, lpUserName, 256)
   If lResult = 0 Then
      GetNetUser = Left$(lpUserName, InStr(1, lpUserName, Chr$(0)) - 1)
   Else
      GetNetUser = "-unknown-"
   End If
End Function

It can be used in a query as GetNetUser() and in the control source of a text box on a form or report as =GetNetUser()