Public Function Q

J

Jack

What is the best way? Sample 1 or 2


Public Function UserSecurity()
On Error GoTo EndIt

Dim strSQL, strCurUserID As String
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection

strCurUserID = ThisUser

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT tblSecurity.UserID, tblSecurity.
cmdCustomer from tblSecurity where UserID = '" &
strCurUserID & "'"

rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly

On Error Resume Next
===========
Sample 1
============
If rs.Fields() = False Then
Forms![MainMenu]![cmdCustomer].Enabled = False
End If

==========
Sample 2
=========
If rs.Fields() = True Then
Forms![MainMenu]![cmdCustomer].Enabled = True
End If
 
D

Dirk Goldgar

Jack said:
What is the best way? Sample 1 or 2


Public Function UserSecurity()
On Error GoTo EndIt

Dim strSQL, strCurUserID As String
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection

strCurUserID = ThisUser

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT tblSecurity.UserID, tblSecurity.
cmdCustomer from tblSecurity where UserID = '" &
strCurUserID & "'"

rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly

On Error Resume Next
===========
Sample 1
============
If rs.Fields() = False Then
Forms![MainMenu]![cmdCustomer].Enabled = False
End If

==========
Sample 2
=========
If rs.Fields() = True Then
Forms![MainMenu]![cmdCustomer].Enabled = True
End If

Did you mean to include the field cmdCustomer in your reference to
"rs.Fields()"? I don't see how it's going to work, otherwise.

Assuming you did intend to write

If rs.Fields(cmdCustomer) ...

I don't see any particular difference between the two code snippets, in
terms of the outcome or efficiency. I'd probably simplify it to this
one line, though:

Forms![MainMenu]![cmdCustomer].Enabled = rs.Fields(cmdCustomer)
 
J

Jack

In the previous example there was no difference, however
in the example below the "cmdCustomerPlaceEditOrder"
button will be enabled when using the code below. It will
only be disabled
With cod e Example 1 or 2

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT tblSecurity.UserID,
tblSecurity.cmdCustomer,
tblSecurity.cmdCustomerPlaceEditOrder from tblSecurity
where UserID = '" & strCurUserID & "'"

rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly

On Error Resume Next


If rs.Fields(2) = True Then
Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = True
End If


Example 1

If rs.Fields(2) = False Then
Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = False
End If


Example 2

Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = rs.Fields(2)

Why doesn't this work with example 1?
 
D

Dirk Goldgar

Jack said:
In the previous example there was no difference, however
in the example below the "cmdCustomerPlaceEditOrder"
button will be enabled when using the code below. It will
only be disabled
With cod e Example 1 or 2

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT tblSecurity.UserID,
tblSecurity.cmdCustomer,
tblSecurity.cmdCustomerPlaceEditOrder from tblSecurity
where UserID = '" & strCurUserID & "'"

rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly

On Error Resume Next


If rs.Fields(2) = True Then
Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = True
End If


Example 1

If rs.Fields(2) = False Then
Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = False
End If


Example 2

Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = rs.Fields(2)

Why doesn't this work with example 1?

What is the data type of the field cmdCustomerPlaceEditOrder in
tblSecurity? What type of database (Jet, SQL Server, other) is
tblSecurity defined in?
 
D

Dirk Goldgar

Jack said:
I'm using only Ms- Access.
The Data type is Yes/No
Thanks


-----Original Message-----
Jack said:
Example 1

If rs.Fields(2) = False Then
Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = False
End If


Example 2

Forms![CustomerMainMenu]!
[cmdCustomerPlaceEditOrder].Enabled = rs.Fields(2)

Why doesn't this work with example 1?

What is the data type of the field cmdCustomerPlaceEditOrder in
tblSecurity? What type of database (Jet, SQL Server, other) is
tblSecurity defined in?

I don't see the problem offhand, except that of course you can't disable
a control that has the focus. So if the button
cmdCustomerPlaceEditOrder currently has the focus, any statement that
attempts to set its Enabled property to False will fail. Could that be
what's happening? You have an "On Error Resume Next" in effect, so you
wouldn't get the error message relevant to this failure/

If that's not the problem, set a breakpoint in the routine and trace its
execution to see what happens and what the values of variables,
properties, and fields are.
 

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