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 = "Edit Mode On"
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] & "
" & [FirstName] AS Name
FROM Employees
ORDER BY Employees.LastName, Employees.FirstName;
In ComboBox EmployeeID the bound column is set to 1
Fule
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 = "Edit Mode On"
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] & "
" & [FirstName] AS Name
FROM Employees
ORDER BY Employees.LastName, Employees.FirstName;
In ComboBox EmployeeID the bound column is set to 1
Fule