advapi32.dll

J

JimS

I've had the fosusername() function running on a client's computer for a long
time. Suddenly, it can't find the "tacomp90.ocx" library when executing
fOSUsername().
The function references "advapi32.dll" and errors out on a function call:

strUserName=String$(254,0)


Here's the code, straight from the MVP web site. Strangely, it works on my
computer, and not on hers:

Note: I did add in FMS codetools, etc to my computer, used on that database.
But that doesn't seem to be the module it's having troubles with...

Option Compare Database
Global glbUserName As String
Global glbUserId As String
Global glbUserAuthLevel As Long
Global glbModuleID As Byte

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() 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
fOSUserName = UCase(Left$(strUserName, lngLen - 1))
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************
 
D

Douglas J. Steele

If that specific line is causing you problems, it has nothing to do with
advapi32.dll: it's almost guaranteed to be a problem with your References
collection.

Go into the VB Editor and select Tools | References from the menu bar.
Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by compiling your application, under the Debug
menu), go back in and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top