Click and lock

  • Thread starter Thread starter Susy
  • Start date Start date
S

Susy

Can I lock a field when a user clicks it?

That is, is it possible to set up a form with a yes/no
field that, if clicked, restricts the user from going any
farther until he enters data in some required fields?

I have the form and I've done conditional formatting to
hide the fields until the box is clicked, plus I've added
a message box to prompt the user to enter the data, but I
can't MAKE him actually enter the data.

Is there a way to do this?

Thanks.
 
Susy,
Yes there are ways to do all these things.
But I will save you (and your users) a lot of heartache - there is no need
to do any of them.
====================================================================

You can use a procedure like this to validate as many controls as you like
before the record is saved. Note: you don't always have to set Cancel =True.
Your validation could include checking for Null values and simply filling
them in with a "default" value in your code.

If everything passes the validation, there will be no message box because
Cancel will be False and the record will save.

If anything fails, then Cancel will be True and the user will see the
problem and can fix it and try to save the record again.


Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMessage As String

If Me![txt1] < 0 Or Me![txt2] > 100 Then
strMessage = strMessage & vbCrLf & "Value must be between 0 and 100."
Cancel = True
End If

If Left$(Me![txtTableName], 3) = "tbl" Then
strMessage = strMessage & vbCrLf & "New table names cannot start with
tbl."
Cancel = True
End If

If IsNull(Me![EmailAddress]) Then
strMessage = strMessage & vbCrLf & "Please enter an E-mail address
before saving the record."
Cancel = True
End If

If Cancel = True Then
MsgBox (strMessage)
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source &
vbCrLf & Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate

End Sub
 
I didn't explain correctly.

The yes/no box is a choice for the user. "Yes" he censors
that data point, "No" he doesn't.

If he censors that data point, I want him to justify it in
a comments box and add today's date and his initials. I
can prompt him but I can't stop him from clicking "Yes"
and just moving on without entering the justification.

(If he censors the data, that data point doesn't appear on
the graph on the form.)

This is probably too confusing...

Thanks, Susy

-----Original Message-----
Susy,
Yes there are ways to do all these things.
But I will save you (and your users) a lot of heartache - there is no need
to do any of them.
========================================================== ==========

You can use a procedure like this to validate as many controls as you like
before the record is saved. Note: you don't always have to set Cancel =True.
Your validation could include checking for Null values and simply filling
them in with a "default" value in your code.

If everything passes the validation, there will be no message box because
Cancel will be False and the record will save.

If anything fails, then Cancel will be True and the user will see the
problem and can fix it and try to save the record again.


Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMessage As String

If Me![txt1] < 0 Or Me![txt2] > 100 Then
strMessage = strMessage & vbCrLf & "Value must be between 0 and 100."
Cancel = True
End If

If Left$(Me![txtTableName], 3) = "tbl" Then
strMessage = strMessage & vbCrLf & "New table names cannot start with
tbl."
Cancel = True
End If

If IsNull(Me![EmailAddress]) Then
strMessage = strMessage & vbCrLf & "Please enter an E- mail address
before saving the record."
Cancel = True
End If

If Cancel = True Then
MsgBox (strMessage)
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source &
vbCrLf & Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate

End Sub
--
Joe Fallon
Access MVP



Can I lock a field when a user clicks it?

That is, is it possible to set up a form with a yes/no
field that, if clicked, restricts the user from going any
farther until he enters data in some required fields?

I have the form and I've done conditional formatting to
hide the fields until the box is clicked, plus I've added
a message box to prompt the user to enter the data, but I
can't MAKE him actually enter the data.

Is there a way to do this?

Thanks.


.
 
You can add things "automatically" to records like current date/time and
userID using the AfterUpdate event of the form or one of its controls.

You can use the same event to force the user into a text box.
(Of course you can't make him fill out correctly - just enter something.)
--
Joe Fallon
Access MVP



Susy said:
I didn't explain correctly.

The yes/no box is a choice for the user. "Yes" he censors
that data point, "No" he doesn't.

If he censors that data point, I want him to justify it in
a comments box and add today's date and his initials. I
can prompt him but I can't stop him from clicking "Yes"
and just moving on without entering the justification.

(If he censors the data, that data point doesn't appear on
the graph on the form.)

This is probably too confusing...

Thanks, Susy

-----Original Message-----
Susy,
Yes there are ways to do all these things.
But I will save you (and your users) a lot of heartache - there is no need
to do any of them.
========================================================== ==========

You can use a procedure like this to validate as many controls as you like
before the record is saved. Note: you don't always have to set Cancel =True.
Your validation could include checking for Null values and simply filling
them in with a "default" value in your code.

If everything passes the validation, there will be no message box because
Cancel will be False and the record will save.

If anything fails, then Cancel will be True and the user will see the
problem and can fix it and try to save the record again.


Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMessage As String

If Me![txt1] < 0 Or Me![txt2] > 100 Then
strMessage = strMessage & vbCrLf & "Value must be between 0 and 100."
Cancel = True
End If

If Left$(Me![txtTableName], 3) = "tbl" Then
strMessage = strMessage & vbCrLf & "New table names cannot start with
tbl."
Cancel = True
End If

If IsNull(Me![EmailAddress]) Then
strMessage = strMessage & vbCrLf & "Please enter an E- mail address
before saving the record."
Cancel = True
End If

If Cancel = True Then
MsgBox (strMessage)
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source &
vbCrLf & Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate

End Sub
--
Joe Fallon
Access MVP



Can I lock a field when a user clicks it?

That is, is it possible to set up a form with a yes/no
field that, if clicked, restricts the user from going any
farther until he enters data in some required fields?

I have the form and I've done conditional formatting to
hide the fields until the box is clicked, plus I've added
a message box to prompt the user to enter the data, but I
can't MAKE him actually enter the data.

Is there a way to do this?

Thanks.


.
 
Back
Top