Enable/Disable Text Fields

T

Trini Gal

Hello,

I've searched through posting and I haven't been able to find what I'm
looking for so I'm not even sure if this is possible.

I have a form, which requires 3 different individual's approval: Person1,
Person2, Person3. When the form loads, I have all threes fields enabled,
with a command button next to them that is enabled: Approved.

I want the individual to be able to click on "Approved" and have a form pop
up asking for password, which is checked against the password I have stored
in a table. If the password is a match, I want the "Name" in the table thats
associated with the password to show up in the field, and then disable the
field so changes can't be made.

Is this possible?
 
J

Jeanette Cunningham

Yes, it's possible.
I suggest that those 3 fields are always disabled, so that the only way a
name can be entered is using the password form.
To tackle this project, take it one step at a time.

Write the code to open the popup form when the approved button is clicked.
When you have this bit working, then add the password field to the popup.
When this is working, do the code to check the entered password against the
password stored in the table.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

J_Goddard via AccessMonster.com

Hi -

In addition to Jeanette's suggestions, you might want to add code to disable
the approval buttons where approval has already been given. You won't need to
do that if your code limits each of your three approval fields to approval by
one and only one person.

HTH

John
 
T

Trini Gal

This is the code I have associated with the "Approve" Button:

Private Sub Command108_Click()
On Error GoTo Err_Command108_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmApprove"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command108_Click:
Exit Sub

Err_Command108_Click:
MsgBox Err.Description
Resume Exit_Command108_Click

End Sub

This is the code I have attached to the button on the "Approval" form:


Private Sub cmdPassword_Click()

Dim stDocName As String

stDocName = "frmCCR_Revise"

If Me.txtTPassword.Value = DLookup("strPassword", "tblTitle") Then

End If

End Sub

This is where I'm stuck. This is as far as my minimal amount of coding
experience will take me. If you can help me out I would really appreciate it.

Thanks in advance.
 
T

Trini Gal

Hi,

Thanks for your suggestion, I didn't even think about that. Do you have any
code to get me started?
 
J

J_Goddard via AccessMonster.com

Hi -

I'm assuming that the names of the persons giving the approvals are kept in
the table underlying your main form, and that the three corresponding
controls on the form are [person1], [person2] and [person3], and that the
approval buttons are Approval1, 2 and 3 you could put something like this in
the On Current event of the form:

me!Approval1.enabled = True
me!Approval2.enabled = True
me!Approval3.enabled = True

if len(trim(nz(me![Person1],""))) > 0 then me!Approval1.enabled = False
if len(trim(nz(me![Person2],""))) > 0 then me!Approval2.enabled = False
if len(trim(nz(me![Person3],""))) > 0 then me!Approval3.enabled = False

This first resets all the Approval buttons to enabled, then disables those
where the approval has already been given. This part: len(trim(nz(me!
[Person1],""))) > 0 converts nulls to zero-length strings, removes any
leading/trailing blanks, and checks the length of the resulting string. It
covers all cases of no data ( Blank <> Zero length string <> Null).

HTH

John




Trini said:
Hi,

Thanks for your suggestion, I didn't even think about that. Do you have any
code to get me started?
[quoted text clipped - 23 lines]
 
T

Trini Gal

John,

Thanks for the code.

This is the code I have attached to the "Approve1" button on the
frmCCR_Revise form:

Private Sub cmdRVP_Click()
On Error GoTo Err_cmdRVP_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRVPApprove"

stLinkCriteria = "[CCR_ID]=" & Me![CCR_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdRVP_Click:
Exit Sub

Err_cmdRVP_Click:
MsgBox Err.Description
Resume Exit_cmdRVP_Click

End Sub

I was wondering if you could help me with the following:

Private Sub cmdTitleApprove_Click()

'Check to see if data is entered into the Title combo box

If IsNull(Me.cmdTitle) Or Me.cmdTitle = "" Then
MsgBox "You must select a Region.", vbOKOnly, "REQUIRED DATA"
Me.cmdTitle.SetFocus

Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtTitlePassword) Or Me.txtTitlePassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "REQUIRED DATA"
Me.txtTitlePassword.SetFocus
Exit Sub
End If

'Check value of password in the tblTitle table to see if this
'matches value chose in the combo box

If Me.txtTitlePassword.Value = DLookup("strPassword", "tblTitle",
"[TitleID]=" & Me.cmdTitle.Value) Then
TitleID = Me.cmdTitle.Value

***********If the password match, I want the system to insert the name of
the person in the frmCCR_Revise form here and close this form***************


'Close logon form and open the frmCCR_Revise


Else
MsgBox "Password Invalid. Please Try Again.", vbOKOnly, "INVALID ENTRY!"
Me.txtTitlePassword.SetFocus
End If

'If User Enter incorrect password 3 times database will shut down

intLogonAttempts = intLogonAttempt + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact the
Databas Administrator.", vbCritical, "RESTRICTED ACCESS!"
Application.Quit
End If

Exit_cmdGoTypeForm_Click:
Exit Sub

Err_cmdGoTypeForm_Click:
MsgBox Err.Description
Resume Exit_cmdGoTypeForm_Click

End Sub


J_Goddard via AccessMonster.com said:
Hi -

I'm assuming that the names of the persons giving the approvals are kept in
the table underlying your main form, and that the three corresponding
controls on the form are [person1], [person2] and [person3], and that the
approval buttons are Approval1, 2 and 3 you could put something like this in
the On Current event of the form:

me!Approval1.enabled = True
me!Approval2.enabled = True
me!Approval3.enabled = True

if len(trim(nz(me![Person1],""))) > 0 then me!Approval1.enabled = False
if len(trim(nz(me![Person2],""))) > 0 then me!Approval2.enabled = False
if len(trim(nz(me![Person3],""))) > 0 then me!Approval3.enabled = False

This first resets all the Approval buttons to enabled, then disables those
where the approval has already been given. This part: len(trim(nz(me!
[Person1],""))) > 0 converts nulls to zero-length strings, removes any
leading/trailing blanks, and checks the length of the resulting string. It
covers all cases of no data ( Blank <> Zero length string <> Null).

HTH

John




Trini said:
Hi,

Thanks for your suggestion, I didn't even think about that. Do you have any
code to get me started?
[quoted text clipped - 23 lines]
Is this possible?

--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca



.
 
J

J_Goddard via AccessMonster.com

Good morning -

I'll start with the login form - I assume cmdTitleApprove is a command
button on it (if not what form is it on?)
If Me.txtTitlePassword.Value = DLookup("strPassword", "tblTitle",
"[TitleID]=" & Me.cmdTitle.Value) Then
TitleID = Me.cmdTitle.Value

1)You don't need to use .Value - just the name of the control is sufficient
2)If me!cmdTitle is text, then you need to enclose it in quotation marks
(single-quotes work)
3)What is TitleID? If it a variable, and it is not explicitly declared
outside this Sub (with a Dim statement), then it will not be recognized
outside this sub.

So now you have this:

If Me.txtTitlePassword = DLookup("strPassword", "tblTitle",
"[TitleID] = '" & Me.cmdTitle & "'") Then
TitleID = Me.cmdTitle
***********If the password match, I want the system to insert the name of
the person in the frmCCR_Revise form here and close this form***************

'Close logon form and open the frmCCR_Revise

OK, but what field do you want to put the name in? And you can't do that
until the form is opened:

Docmd.openform "frmCCR_Revise"
forms!frmCCR_Revise!fieldName = TitleID
Forms!cmdTitleApprove.close
exit sub
intLogonAttempts = intLogonAttempt + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact the
Databas Administrator.", vbCritical, "RESTRICTED ACCESS!"
Application.Quit
End If

I don't know where (or if) you declared intLogonAttempts as a variable, but
in order for this to work, it must be declared (with a Dim statement) outside
this Sub. Otherwise it is reset to 0 each time the button is clicked.

Once you have put title_ID in to frmCCR_Revise!fieldName , what do you
intend to do with it?



Now, for the Approve1 button code:

It doesn't do anything other than to open another form.

What does frmRVPApprove do, and what is its recordsource? And how is it
closed?

Hope this gets you further.

John




Trini said:
John,

Thanks for the code.

This is the code I have attached to the "Approve1" button on the
frmCCR_Revise form:

Private Sub cmdRVP_Click()
On Error GoTo Err_cmdRVP_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmRVPApprove"

stLinkCriteria = "[CCR_ID]=" & Me![CCR_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdRVP_Click:
Exit Sub

Err_cmdRVP_Click:
MsgBox Err.Description
Resume Exit_cmdRVP_Click

End Sub

I was wondering if you could help me with the following:

Private Sub cmdTitleApprove_Click()

'Check to see if data is entered into the Title combo box

If IsNull(Me.cmdTitle) Or Me.cmdTitle = "" Then
MsgBox "You must select a Region.", vbOKOnly, "REQUIRED DATA"
Me.cmdTitle.SetFocus

Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtTitlePassword) Or Me.txtTitlePassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "REQUIRED DATA"
Me.txtTitlePassword.SetFocus
Exit Sub
End If

'Check value of password in the tblTitle table to see if this
'matches value chose in the combo box

If Me.txtTitlePassword.Value = DLookup("strPassword", "tblTitle",
"[TitleID]=" & Me.cmdTitle.Value) Then
TitleID = Me.cmdTitle.Value

***********If the password match, I want the system to insert the name of
the person in the frmCCR_Revise form here and close this form***************

'Close logon form and open the frmCCR_Revise


Else
MsgBox "Password Invalid. Please Try Again.", vbOKOnly, "INVALID ENTRY!"
Me.txtTitlePassword.SetFocus
End If

'If User Enter incorrect password 3 times database will shut down

intLogonAttempts = intLogonAttempt + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact the
Databas Administrator.", vbCritical, "RESTRICTED ACCESS!"
Application.Quit
End If

Exit_cmdGoTypeForm_Click:
Exit Sub

Err_cmdGoTypeForm_Click:
MsgBox Err.Description
Resume Exit_cmdGoTypeForm_Click

End Sub
[quoted text clipped - 32 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top