Driving me bonkers

  • Thread starter Thread starter martinmike2
  • Start date Start date
M

martinmike2

Hello,

I know this should be easy but I have been staring at the same 15
lines of code for the past 2 hours to no avail.

Code:

Private Sub Form_Open(Cancel As Integer)
Dim bok As Boolean
bok = EnableDisableControls("frmMain", 0, False)
If bok = False Then
If MsgBox("There has been an error, contact Manpower to resolve
this issue.", vbOKOnly, gstrAppTitle) = vbOK Then
DoCmd.Quit
End If
End If
If gALEVEL = 4 Then
bok = EnableDisableControls("frmMain", 0, True)
End If
DoCmd.Close acForm, "frmLogin"
With Me
..cmdEPERS.Enabled = True
..cmdExit.Enabled = True
..pgADMIN.Enabled = True
End With
End Sub



"EnableDisableControls" does just as its name implies. My problem is
that cmdExit will enable but cmdEPERS will not, no what I try with
it......any ideas?
 
The Open event may be too soon: the form may not be completely instantiated.

Try putting that code in the form's Load event instead.
 
no joy. same problem. I moved the With group to the Form_Load event,
nothing changed.
 
Is there anything different about the two controls? For example, is one in
an option group or on a tab that's not enabled?
 
i didint even think about the tab.

New Code (still dosnt work)

With ME
..pgMain.enabled = true
..cmdEPERS.enabled = true
..Exit.enabled = true
end with
 
That reinforces my belief that Open was incorrect. I'm afraid, though, that
I don't see why it wouldn't work in the Load event.

What's the exact code you put in the Load event?
 
Private Sub Form_Load()
With Me
.pgMAIN.Enabled = True
.cmdEPERS.Enabled = True
.cmdExit.Enabled = True
End With
End Sub
 
I'm really stretching now...

Private Sub Form_Load()
On Error GoTo EH

With Me
.pgMAIN.Enabled = True
MsgBox "Before: cmdEPERS.Enabled = " & _
.cmdEPERS.Enabled
.cmdEPERS.Enabled = True
MsgBox "After: cmdEPERS.Enabled = " & _
.cmdEPERS.Enabled
.cmdExit.Enabled = True
End With

EndIt:
Exit Sub

EH:
MsgBox Err.Number & ": " & Err.Description
Resume EndIt

End Sub

Anything?
 
Douglas said:
I'm really stretching now...

Private Sub Form_Load()
On Error GoTo EH

With Me
.pgMAIN.Enabled = True
MsgBox "Before: cmdEPERS.Enabled = " & _
.cmdEPERS.Enabled
.cmdEPERS.Enabled = True
MsgBox "After: cmdEPERS.Enabled = " & _
.cmdEPERS.Enabled
.cmdExit.Enabled = True
End With

EndIt:
Exit Sub

EH:
MsgBox Err.Number & ": " & Err.Description
Resume EndIt

End Sub

Anything?
Another dot in the shark...

What does ME refer to? Is cmdEPERS a member of it?
Mike
 
Since this code is in the forms module, Me refers to the form.
cmdEPERS is a member of Me.Controls.

Thank you for sticking with me, but I have decided to abandon this
technique for this form, what I have done is just hide the controls I
dont want a particular access level to see.

Code:
Private Sub Form_Load()
Dim bok As Variant
With Me
..pgMAINT.Visible = False
..pgMANPOWER.Visible = False
..Page135.Visible = False
..Page136.Visible = False
..Page137.Visible = False
..cmdRESLOG.Visible = False
..cmdOPERS.Visible = False
End With

If gALEVEL = 4 Then
bok = EnableDisableControls("frmMain", 0, True)
End If
DoCmd.Close acForm, "frmLogin"

End Sub

this worked as expected and seems to have solved the overriding
problem of limiting access levels.

(I had originally gone to a usergroup, but it caused more problems
than it solved)

My users have a bad habit of locking the computer with the program
still running with the effect of putting the database in a suspicious
state and locking out everybody. When the offender would return to
their desk, I would have to get them out of the system and then run
the shortcut with /repair so it could be used again.

If I could devise/find some code to make access exit when Windows
starts to go into its locked state I would go back to the usergroup,
as im not sure how im going to deal with the Open Exclusive issue in
this split db.
 
hi Martin,
Code:
With Me
.pgMAINT.Visible = False
.pgMANPOWER.Visible = False
.Page135.Visible = False
.Page136.Visible = False
.Page137.Visible = False
.cmdRESLOG.Visible = False
.cmdOPERS.Visible = False
End With
There is no reason for using the "With Me" - block. You may simply use,
e.g. pgMAINT.Visible = False. This addresses the control correctly.

I'm normally using the Me only when I use members/properties of the form
itself, e.g. Me.Dirty = False.

btw, where is the focus when you disable your command? Because you
cannot disable it, if it has the focus. Maybe it works when you set the
focus to another control.


mfG
--> stefan <--
 
Back
Top