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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get UserID

Status
Not open for further replies.

fule12

Programmer
Nov 12, 2001
140
YU
Hi all,

I have this two code :
First is module:
---------------- start ---------------------------
Option Compare Database

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

Function ap_GetUserName() As Variant

Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long

'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255

'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)

'-- Assign the value
ap_GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)

End Function
----------------------------- END -----------------------------
Second one is in Switch board and on open event a have Call Validate User
------------------ Start ---------------------------------------
Public Function ValidateUser()

'Confirm that the user should be able to enter this database
Dim db As DAO.Database, rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Username FROM Employees WHERE
username = """ & UCase(ap_GetUserName) & """;")

'Check to see if the user name is in the list of valid users
If rst.EOF Then
MsgBox "You are not authorized to use this database!" & vbNewLine &
_
"Please contact the IT Department for permission.", _
vbCritical, "No Authorization"
rst.Close
Set rst = Nothing
Set db = Nothing
Application.Quit
End If

rst.Close
Set rst = Nothing
Set db = Nothing

End Function

All this is working ok but I have problem . Before in form Order I have
combobox EmployeesID so user found his name and selected so in table orders
for each order I have Employer ID (what is Number).But now on same form I create
Edit button so if user make same
changes hi need to press edit button and if in comboBox is name from another user i whant too be change to mane who edit record

So on click event for Edit Button is this code :

Private Sub cmdEditMode_Click()
if Me.EmployeeID.Column(1)<> ap_GetUserName() Then
Me.EmployeeID.Column(1) = ap_GetUserName()
End If
With Me
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With

Me.cmdEditMode.Caption = &quot;Edit Mode On&quot;
End Sub
But I get run time error ‘424’ – Object required
on this line :

Me.EmployeeID.Column(1) = ap_GetUserName()

And Query for emploee Combobox is :

SELECT DISTINCTROW Employees.EmployeeID, Employees.UserName, [LastName] & &quot;
&quot; & [FirstName] AS Name
FROM Employees
ORDER BY Employees.LastName, Employees.FirstName;
In ComboBox EmployeeID the bound column is set to 1

Fule
 
First &quot;thanks&quot; for hepl

I found Solution

On my form i create text field and source is : =
=DLookUp(&quot;[employeeid]&quot;,&quot;Employees&quot;,&quot;UserName = '&quot; & ap_GetUserName() & &quot;'&quot;)
and code in Edit button is :

Private Sub cmdEditMode_Click()
If Me.EmployeeID.Column(1) <> ap_GetUserName() Then
Me.EmployeeID = txtUsername

End If
With Me
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With

Me.cmdEditMode.Caption = &quot;Edit Mode On&quot;
End Sub
Fule
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top