Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Office VBA Question 2

Status
Not open for further replies.

tgmoon

Technical User
Jan 31, 2001
54
GB
I hope that i can put this clearly. I need to reference to a specific file in a users directory which is the same for all users, the only difference being the username, i.e. below. Is there any bit of code that can autmatically get the users NT/XP login name and insert it.

\\rs0012\moto\files\, where moto is the username
 
Hi tgmoon,

[blue]Environ("Username")[/blue] should do it for you.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
there is also this code for a module in access.

Option Compare Database
Option Explicit

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Const cPassword = "TMBG"

'Code courtesy of
'Dev Ashish
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 = ""
End If
End Function


Function AddUser()
Dim strdB As String, db As DAO.Database, rsNew As DAO.Recordset, rsAdd As DAO.Recordset
On Error GoTo AddUser_Error
strdB = ahtCommonFileOpenSave(ahtOFN_FILEMUSTEXIST, , "Database Password File (*.pwd)" & vbNullChar & "*.pwd" & vbNullChar)
If strdB = "NoFile" Then Exit Function
Set db = Application.DBEngine.OpenDatabase(strdB, False, False, "MS Access;PWD=" & cPassword & ";DATABASE=" & strdB)
Set rsNew = db.OpenRecordset("tblUser")
Set rsAdd = CurrentDb.OpenRecordset("tblAdmin")
rsNew.MoveFirst

rsAdd.AddNew
rsAdd(0) = rsNew(0)
rsAdd(1) = rsNew(1)
rsAdd(2) = rsNew(2)
rsAdd.Update

rsNew.Delete
AddUser_Exit:
Exit Function

AddUser_Error:
Select Case Err
Case Is = 3022
rsAdd.CancelUpdate
If MsgBox("User " & rsNew(0) & " Already Exists. Do You Wish To Reset The Password?", vbCritical + vbYesNo, "Performance And Strategic Planning") = vbYes Then
rsAdd.FindFirst "[EmployeeNumber]='" & rsNew!EmployeeNumber & "'"
rsAdd.Edit
rsAdd!Password = rsNew!Password
rsAdd!Level = rsNew!Level
rsAdd.Update
End If
Resume Next
Case Is = 3021
MsgBox "Your Password File Is Empty." & Chr$(10) & "Contact Performance Review On 22891 To Receive A New File.", vbExclamation + vbOKOnly, "Performance And Strategic Planning"
Resume AddUser_Exit
Case Else
MsgBox Err & Chr$(10) & Err.Description
Resume AddUser_Exit
End Select
End Function
 
Thanks for the replys everyone, but i'm afraid they've gone a little over my head. How would i utilise it to replace the "moto" with whoever is logged on?

ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="\\lonres001\UserData\moto\My Documents\aaaaa.jpg")
 
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="\\lonres001\UserData\" & environ("username") & "\My Documents\aaaaa.jpg")

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top