Date restriction.

yeppy12

Registered User.
Local time
Today, 12:38
Joined
Sep 11, 2007
Messages
38
I have a form with a date field (Start Date). I want to limit who can enter/alter a date once it is entered...for example, Bob, Joe, and Jane all use the form, but only Joe should be allowed to change it.
 
yeppy,

Use the date field's GotFocus event:

Code:
Private Sub txtDateField_GotFocus()
If Environ("UserName") = "Joe" Then
  Me.txtDateField.Locked = False
Else
  If Len(Nz(Me.Text6)) = 0 Then
     Me.txtDateField.Locked = False
  Else
     Me.txtDateField.Locked = True
  End If
End If
End Sub

hth,
Wayne
 
I have 2 questions about the If statements. For the
Code:
If Environ("UserName") = "Joe"
statement, is "UserName" suppoesed to be a field on my form?
Also, for the
Code:
If Len(Nz(Me.Text6)) = 0
statement, what is Me.Text6 supposed to be?
 
Wayne appears to be offline, so I'll make an attempt to assist here.

1) No, "UserName" is a specific argument for the function. It will return the Windows user.

2) Based on context, I'm guessing that would be the control on the form containing the record ID. If it's blank, it's a new record, so unlock the field. You could probably also use:

If Me.NewRecord
 
Okay. Is it possible to just have the first part of the code? My form only has 3 fields, none of which is a record ID. My thinking is that once a person logs into Windows and opens my form, he/she would only be able to fill in certain fields. Thanks in advance.

Code:
Private Sub txtDateField_GotFocus()
If Environ("UserName") = "Joe" Then
  Me.txtDateField.Locked = False
End If
End Sub
 
yeppy,

Paul was right.

The "text6" was just a cut-and-paste error.

Code:
Private Sub txtDateField_GotFocus()
If Environ("UserName") = "Joe" Then  <-- Or wherever you have the username
  Me.txtDateField.Locked = False     <-- Joe can edit anytime
Else
  If Len(Nz(Me.txtDateField)) = 0 Then  <-- Others can only type in values
     Me.txtDateField.Locked = False     <-- if the field is blank
  Else
     Me.txtDateField.Locked = True      <-- If it has a value and you're not Joe
  End If
End If
End Sub

Wayne
 
Thanks for the help. Everything works just fine.
 

Users who are viewing this thread

Back
Top Bottom