Asks user name before quits form? (1 Viewer)

Matthew Lamkin

Registered User.
Local time
Today, 10:49
Joined
Oct 25, 2001
Messages
21
Hello, when the exit form button is pressed, how can I check that a field has got a users initials in it?

My database is used to store modification note details and when a new record is created I want each user to identify themselves on the record.
But some will undoubtably not bother so I want the form to refuse to quit and pop up a message box saying that it will not until they have entered thier name into a field?
How?
Thankyou.
 
D

DJN

Guest
It would be better to capture the user name and add that to the record in the table. Add a new field to the table, say UserID and place this code in the Before Update Event procedure of the form.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UserID = GetNTUser & " " & Date
End Sub

Add this function to a module.

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


Public Function GetNTUser() As String
'Returns the network login name
Dim strUserName As String
'Create a buffer
strUserName = String(100, Chr$(0))
'Get user name
GetUserName strUserName, 100
'Strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
GetNTUser = strUserName
End Function

Now, the user name and date will be added to the record in the table automatically without the user ever knowing.

Or you could trap the error at form level with this sub.

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

Const adhcErrFieldNull = 3314

If adhcErrFieldNull Then
MsgBox "Required", vbCritical, "Required Field"
DateRaised.SetFocus
Exit Sub
End If

DoCmd.Close acForm, "frmFormName”

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

Hope that this proves useful.

David
 

Matthew Lamkin

Registered User.
Local time
Today, 10:49
Joined
Oct 25, 2001
Messages
21
Hello David, thank you for your reply.
It may come to what you have mentioned, but what I really want to do is have the name or initials typed in, as "I" may be entering them for "others".

As it is I have 1300 entries to backdate into this database once I have set it up.
(long job....)
Any suggestoins for doing it that way?
 
M

mrabrams

Guest
I want the form to refuse to quit and pop up a message box saying that it will not until they have entered thier name into a field?

Option 1:
Create a field in your table UserName and set it's "Required" property to YES.
This will have the internal Access message box pop up - "required field"..etc

Option 2:
Similar to what David offered:

In the Before Update event of the form:
If IsNull(yourfield) Then
MsgBox "Required", vbCritical, "Required Field"
Cancel = True
Exit Sub

Let us know.

Michael Abrams
 

Users who are viewing this thread

Top Bottom