Environ("username") VS fOSUserName

V

Victoria

Hello,

I am trying to create an order number using UserID + counter due to
the fact tha my database will be distributed to about 20 end user to
be used to place orders at the convention. I so allot on the toping
and copied allot of code back an forth with no luck untill I stumbled
upone environ("username") function. I placed in to the default field
in my UderID text box on my form and it works fine. However, I just
emailed a copy to my collegue and when he open the database, the
username was not shoing up as part of the order number.

Please help.
I have found the following code for FOSUserName function which
everyone seems to say is more relaiable than environ(usernma).
However, I placed it in a module as per instructions and called the
module for FOSUserName. When I run the I get a compile error before
for (by Val IpBuffer....)

Option Compare Database
' 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 = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function

Can some one please help me get the userid from the network? I would
need specific instructions for the code and where to call it from. My
filed in my form is called UserID, and it is in Orders form. I have to
distribute the database in few days.

Thank you,
Victoria
 
D

Douglas J. Steele

Rename the module. Modules cannot be named the same as routines contained
within them.
 
V

Victoria

Rename the module. Modules cannot be named the same as routines contained
within them.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)












- Show quoted text -

It WORKS !!!!
Doug, quick question, now I put the default value of the userID text
boxt to =fOSUserName(). Unlike environ("username"), whill this work
everytime?

I was wondering if you could answer another question for me since you
seem to be knowledgable. I have another function that I have been
stragaling with for days and no matter how I write it, I don't get the
answer that I need. I think I might be miscalling it or not
referencing it right. I have a subtotal text box on the main form
that is just referencing a subtotal textbox from the subform's footer
as its control source. Basically, as the value in that subtotal
changes with every new item added to the order in the orders subfrom,
I would like a value in another text box display one of of three
options. the field that contains the beginning value is found in
[Orders].Form!OrderSubtotalAmex and the field where I would like the
end result diplayed is called [Orders].Form!OrderGifts.

Right now I created a module called AMEX1 and this what have. I'm
getting compile error and I know i'm missing the begining of a
function but I don't know that it should be.

Option Compare Database
Option Explicit ' Requires variables to be declared before they are
used.


Dim MyInput As Currency
Dim MyOutput As Currency

MyInput = [Orders].Form!OrderSubtotalAmex
MyOutput = [Orders].Form!GITS
Select Case MyInput
Case 0 To 2499 '(Or <=2499 to account for negatives)
MyOutput = 0
Case 2500 To 4999
MyOutput = 250
Case Is >= 5000
MyOutput = 600
Case Else
MyOutput = 0
End Select

End Function

Could you please advise.

I have started a thread last week on
http://groups.google.ca/group/comp....5e1ab/f47584dc0e7ca564?hl=en#f47584dc0e7ca564

Victoria
 
D

Douglas J. Steele

Victoria said:
Doug, quick question, now I put the default value of the userID text
boxt to =fOSUserName(). Unlike environ("username"), whill this work
everytime?

It should. For that matter, Environ("Username") should work everytime as
well. It's just that it's trivial to reset environment variables, so if the
user wanted to, he/she could easily reset it while they use your
application.

Add:

Function MyOutput(MyInput As Currency) As Currency

Remove:
Dim MyInput As Currency
Dim MyOutput As Currency

(and follow Jamie's suggestion)
 

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

Top