Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help with a Simple Task, Hiding Controls 2

Status
Not open for further replies.

originalxavier

Programmer
Mar 5, 2003
69
0
0
US
Hey everyone,

I am having some difficulty hiding controls on a form. I have a form with a subform in it. It is a "secure" database requiring a logon and the shift bypass key is disabled so no one can enter the database without authentication. However, I want to make sure that no one can gain access to the forms who is not logged in so I have an "If" statement saying that if there is no user logged in hide all controls.

Code:
Private Sub TestHideCTR_Click()
Dim ctlCurrent As Control
    
'Check to see if a user is logged in.
If lngMyEmpID > 0 Then
    'Perform no action
Else
    'If there is no user logged in, hide all controls
    For Each ctlCurrent In frmCurrent.Controls
        ctlCurrent.Visible = False
    Next ctlCurrent
End If

End Sub

When this code is run I get a "run time error 424" "object required" and it points to "ctlCurrent" which is " = nothing". I am wondering if I forgot to reference a library necessary for this?... Any help would be appreciated.



Xavier

----------------------------------------
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning"
Rick Cook
----------------------------------------
 
What is frmCurrent ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Earth: Me.Controls works (mostly). There are activeX controls that give an error... "This activeX control isn't visible in form view"... Need to debug and see what I can find.

PHV: I was under the impression that this was a built in variable like "CurrentDb". It was taken directly from the MSDN website.

Both... Now that I think about it, as grand an idea as this may be, there are too many controls on the page that need to remain hidden to effectively use this method. I may as well go one by one and hide only the one's that need to be hidden, since if the user is validated, some controls will need to be unhidden while some remain hidden the whole time.

On another note, I have a report that pops an error message on "No Data". Is there any way to stop the report from opening up with a blank page. I am not using a recordset to open in, the code is on another page and is as follows:

Code:
        DoCmd.OpenReport "G570", [acViewPreview], , "[Signature] <> '000000000000000000000000000000000000000000000000000000000000000000000000'"


Xavier

----------------------------------------
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning"
Rick Cook
----------------------------------------
 
Rather than hide the controls - just set then to disabled - that should overcome the ActiveX controls problems

With regard to the report, try (DAO syntax):

dim rs as recordset
set rs = currentdb.openrecordset(yourreportquery)
if not(rs.bof and rs.eof) then
rs.close
set rs = nothing
docmd.openreport etc etc
else
rs.close
set rs = nothing
end if
 
The NoData event procedure of the Report object has an Cancel argument you can play with.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Earth: I will look at the "disable" option. Thanks for your help. I know that this can be done through the DAO recordset but I am trying to avoid it. I know that that is probably the easiest method (there are other reports that open using recordsets), however, I am also doing this to discover/learn all methods and "excercise" my brain.

PHV:I am looking into the Cancel argument now and will update if I can get it to work.
 
PHV: That was insanely simple...

Code:
Private Sub Report_NoData(Cancel As Integer)

MsgBox "There are no records to display, please try again..."
Cancel = True
End Sub

Thanks to both for your help. Very useful/relevant information.
 
A note for anyone trying to use the "Cancel" function of the NoData action event. You will get a "Run-time error '2501': The OpenReport action was cancelled."
In order to get around this, you will need to insert an error handler. Mine looks like this:
Code:
On Error GoTo err_PullAllDataButton_Click

....code....

err_PullAllDataButton_Click:
    If Err.Number = 2501 Then
    Exit Sub
    End If

This will keep the error message from coming up and will not allow anyone to view the code behind your from by pressing "Debug".

Hope this helps someone else.

Xavier

----------------------------------------
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning"
Rick Cook
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top