Enable/Disable

G

Guest

I asked a similar question, but I must try to clearify:

I just want to enable/disable a command button when a form is opened, based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...

Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub

//////////////
Please help....
 
G

Guest

Dan:

Are you having the user login? Are you using a log-in form? Does it have a
password?

Post back and I will try to help
 
G

Guest

YES to all 3 questions.

Public Sub userCheck()
lCriteria = "SELECT DISTINCTROW tblUsers.* FROM tblUsers "
lCriteria = lCriteria & "WHERE (((tblUsers.RACFID)=" & """" &
cboLogonName & """" & ") "
lCriteria = lCriteria & "AND ((tblUsers.Password)=" & """" & txtPassword
& """" & "));"
Set lrs = ldb.OpenRecordset(lCriteria)
End Sub
/////////////////////////////////////////

Randy Wayne said:
Dan:

Are you having the user login? Are you using a log-in form? Does it have a
password?

Post back and I will try to help
--
Thanks,

Randy


Dan @BCBS said:
I asked a similar question, but I must try to clearify:

I just want to enable/disable a command button when a form is opened, based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...

Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub

//////////////
Please help....
 
G

Guest

Dan:

Here is the short version of one way that I like to use.

Use (or create) a simple log-in form. Bind your tblUsers to the form. Make
sure the form is modal.

After the user enters a userId and password, use a Find or FindFirst method
to look up the userID and then verify that the password entered agrees with
the password in that table. If it does not, use a MsgBox to tell the user
they are not validated. You can add code to allow for more than one attempt
or you can close the form, your call.

If the password entered does agree with the password in the tblUsers, hide
the log-in form, but do not close it (set form Visible = False). You may
need to set the log-in form's Modal property to 'No'.

What you will do will simply look for whether or not the log-in form is
open. Below is a function to do this. Place this code in a General module
for use across multiple forms:

Public Function IsOpen(ByVal strFormName As String) As Boolean
'Returns True if specified form is open in Form view

Const conDesignView = 0
Const conObjStateClosed = 0

IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then

If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If

End Function


Then add some code to the Load Envent on the form with the button you want
to enable. This code would look somethong like this:

If IsOpen("LogIn") Then
cmdMyButton.Enabled = True
Else
cmdMyButton.Enabled = False
End If

There are many other ways to this but this will allow you to call the log-in
form as often as you need it. You can even add a field for security level
in the table and form that allows for various options.

Let me know if this helps.


--
Thanks,

Randy


Dan @BCBS said:
YES to all 3 questions.

Public Sub userCheck()
lCriteria = "SELECT DISTINCTROW tblUsers.* FROM tblUsers "
lCriteria = lCriteria & "WHERE (((tblUsers.RACFID)=" & """" &
cboLogonName & """" & ") "
lCriteria = lCriteria & "AND ((tblUsers.Password)=" & """" & txtPassword
& """" & "));"
Set lrs = ldb.OpenRecordset(lCriteria)
End Sub
/////////////////////////////////////////

Randy Wayne said:
Dan:

Are you having the user login? Are you using a log-in form? Does it have a
password?

Post back and I will try to help
--
Thanks,

Randy


Dan @BCBS said:
I asked a similar question, but I must try to clearify:

I just want to enable/disable a command button when a form is opened, based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...

Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub

//////////////
Please help....
 
G

Guest

Wow, did I ever mess up! I pasted code to something else I was working on...
Very sorry that you had to try to answer that.. You asked me 3 questions and
yes to all three.

All I want to do is enable/disable a command button when a form is opened,
based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...
Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub



Randy Wayne said:
Dan:

Here is the short version of one way that I like to use.

Use (or create) a simple log-in form. Bind your tblUsers to the form. Make
sure the form is modal.

After the user enters a userId and password, use a Find or FindFirst method
to look up the userID and then verify that the password entered agrees with
the password in that table. If it does not, use a MsgBox to tell the user
they are not validated. You can add code to allow for more than one attempt
or you can close the form, your call.

If the password entered does agree with the password in the tblUsers, hide
the log-in form, but do not close it (set form Visible = False). You may
need to set the log-in form's Modal property to 'No'.

What you will do will simply look for whether or not the log-in form is
open. Below is a function to do this. Place this code in a General module
for use across multiple forms:

Public Function IsOpen(ByVal strFormName As String) As Boolean
'Returns True if specified form is open in Form view

Const conDesignView = 0
Const conObjStateClosed = 0

IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then

If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If

End Function


Then add some code to the Load Envent on the form with the button you want
to enable. This code would look somethong like this:

If IsOpen("LogIn") Then
cmdMyButton.Enabled = True
Else
cmdMyButton.Enabled = False
End If

There are many other ways to this but this will allow you to call the log-in
form as often as you need it. You can even add a field for security level
in the table and form that allows for various options.

Let me know if this helps.


--
Thanks,

Randy


Dan @BCBS said:
YES to all 3 questions.

Public Sub userCheck()
lCriteria = "SELECT DISTINCTROW tblUsers.* FROM tblUsers "
lCriteria = lCriteria & "WHERE (((tblUsers.RACFID)=" & """" &
cboLogonName & """" & ") "
lCriteria = lCriteria & "AND ((tblUsers.Password)=" & """" & txtPassword
& """" & "));"
Set lrs = ldb.OpenRecordset(lCriteria)
End Sub
/////////////////////////////////////////

Randy Wayne said:
Dan:

Are you having the user login? Are you using a log-in form? Does it have a
password?

Post back and I will try to help
--
Thanks,

Randy


:

I asked a similar question, but I must try to clearify:

I just want to enable/disable a command button when a form is opened, based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...

Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub

//////////////
Please help....
 
G

Guest

Dan:

If you are using a log-in form, then my previous answer still applies.
Another method is to test for a value (i.e. userID) in a table and see if it
exists.

Dim oRS As ADODB.Recordset
Dim strID as String
Dim strSQL As String

strID = Me.txtUserID.Value

strSQL = "SELECT userID FROM [tblUser] WHERE userID= '" & strID & "'"

Set oRS = New ADODB.Recordset
oRS.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockOptimistic

If oRS.EOF And oRS.BOF Then 'There is no match...
Command125.Enabled = False
Else 'There is a match....
Command125.Enabled = True
End If

'Clean up...
oRS.Close
Set oRS = Nothing



Here you create a recordset based upon a SQL statement. That statement
looks for a value (could be userID or password) on your log-in form that
maches a value in the tblUsers. If the recordset is empty - Beginning of
File (BOF) and End of File (EOF) are both true - then it did not find a match
and the button is not enabled. If not BOF and EOF, then it did find a match
and the button is enabled.

Good Luck,

Randy


Dan @BCBS said:
Wow, did I ever mess up! I pasted code to something else I was working on...
Very sorry that you had to try to answer that.. You asked me 3 questions and
yes to all three.

All I want to do is enable/disable a command button when a form is opened,
based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...
Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub



Randy Wayne said:
Dan:

Here is the short version of one way that I like to use.

Use (or create) a simple log-in form. Bind your tblUsers to the form. Make
sure the form is modal.

After the user enters a userId and password, use a Find or FindFirst method
to look up the userID and then verify that the password entered agrees with
the password in that table. If it does not, use a MsgBox to tell the user
they are not validated. You can add code to allow for more than one attempt
or you can close the form, your call.

If the password entered does agree with the password in the tblUsers, hide
the log-in form, but do not close it (set form Visible = False). You may
need to set the log-in form's Modal property to 'No'.

What you will do will simply look for whether or not the log-in form is
open. Below is a function to do this. Place this code in a General module
for use across multiple forms:

Public Function IsOpen(ByVal strFormName As String) As Boolean
'Returns True if specified form is open in Form view

Const conDesignView = 0
Const conObjStateClosed = 0

IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then

If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If

End Function


Then add some code to the Load Envent on the form with the button you want
to enable. This code would look somethong like this:

If IsOpen("LogIn") Then
cmdMyButton.Enabled = True
Else
cmdMyButton.Enabled = False
End If

There are many other ways to this but this will allow you to call the log-in
form as often as you need it. You can even add a field for security level
in the table and form that allows for various options.

Let me know if this helps.


--
Thanks,

Randy


Dan @BCBS said:
YES to all 3 questions.

Public Sub userCheck()
lCriteria = "SELECT DISTINCTROW tblUsers.* FROM tblUsers "
lCriteria = lCriteria & "WHERE (((tblUsers.RACFID)=" & """" &
cboLogonName & """" & ") "
lCriteria = lCriteria & "AND ((tblUsers.Password)=" & """" & txtPassword
& """" & "));"
Set lrs = ldb.OpenRecordset(lCriteria)
End Sub
/////////////////////////////////////////

:

Dan:

Are you having the user login? Are you using a log-in form? Does it have a
password?

Post back and I will try to help
--
Thanks,

Randy


:

I asked a similar question, but I must try to clearify:

I just want to enable/disable a command button when a form is opened, based
on a true/false from another table. The word Table does not work
"Table.tblUser" (tblUser is my veriable)...

Private Sub Form_Open_Click()
If Table.tblUser = True Then
Command125.Enabled = True
Else
Command125.Enable = False
MsgBox "You do not have permission to change this field."
Cancel = True
Me![DateClosed].Undo
End If

End Sub

//////////////
Please help....
 

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