Limit access to a database to a few users.

Hmm, okay, you're going to need to put your code that is present on the frmMain.
 
I made it work by adding the highlighted part in the code below, although it doesn't make sense since this code runs on Form Load....(the code is part of what I have on frmMain...remaining code deals with opening other forms etc.)

Option Compare Database
Private intLogonAttempts As Integer


Private Sub Form_Load()
Me.Visible = True

On Error Resume Next

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim myQuery As String
Dim i As Integer

myQuery = "SELECT * FROM RATusers WHERE NetworkID = '" & Environ("UserName") & "'"

Set db = CurrentDb()
Set rst = db.OpenRecordset(myQuery, dbOpenDynaset, dbSeeChanges)

If Not rst.BOF And Not rst.EOF Then
rst.Edit
rst.Fields("LogonCount") = rst.Fields("LogonCount") + 1
rst.Fields("LastLogon") = Now()
rst.Update

Me.txtSecurityID = rst.Fields("SecurityID")
If Me.txtSecurityID <> 3 Then
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
'For i = 1 To CommandBars.Count
'CommandBars(i).Enabled = False
'Next i
DoCmd.ShowToolbar "Ribbon", acToolbarNo

End If
Me.txtUserID = rst.Fields("UserID")
Me.txtOverride = rst.Fields("SpecialPermissions")
Me.txtPassword = rst.Fields("Password")

DoEvents
Else
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
'For i = 1 To CommandBars.Count
'CommandBars(i).Enabled = False
'Next i
DoCmd.ShowToolbar "Ribbon", acToolbarNo
Me.Dirty = False
Me.Visible = False
DoCmd.OpenForm "frmNewUser", acNormal, , , , acDialog

Do Until Me.Tag = "Continue"
DoEvents
Loop
Me.Visible = True
Me.txtSecurityID = rst.Fields("SecurityID")
Me.txtUserID = rst.Fields("UserID")
Me.txtOverride = rst.Fields("SpecialPermissions")
Me.txtPassword = rst.Fields("Password")
DoEvents

End If

If Me.txtSecurityID <> 3 Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If

Set rst = Nothing
db.Close
Set db = Nothing

If IsDeveloper Then
ChangeProperty "AllowBypassKey", dbBoolean, True
Else
ChangeProperty "AllowBypassKey", dbBoolean, False
End If


Form_Load_Exit:
Exit Sub:

End Sub
 
But please do let me know if you can figure out why that first line is needed?
 
Seems like my post went away... Do you have the Form set to load under Options?
 
I didn't catch that.

Do you mean as in Database options? If that's the case then yes I have specified it as the first form that should load on opening the database...
 
Okay, good.. then I think it's the code and it's *order of events*. I started yesterday, then work got in the way, as it is right now. So, as soon as I get a minute I will finish and post back.

P.S. Oh, you didn't miss anything, my post never posted!
 
I'm using the following code to open a report.

Private Sub cmdFullTimersR_Click()

DoCmd.SelectObject acReport, Me.Name
DoCmd.Minimize
DoCmd.OpenReport "Full Timer - Current Month", acViewNormal, , , acWindowNormal

End Sub

The code is embedded in the button on the form "Audit Tool Summary". However when click the button the code errors as 'The object 'Audit Tool Summary' isn't open.

I'm confused. I use the similar code to open queries (which open in a form) through buttons on the same form. A sample code is below:

Private Sub cmdColl_Click()

DoCmd.SelectObject acForm, Me.Name
DoCmd.Minimize
DoCmd.OpenForm "Variable Coll - Current Month", acNormal, , , acFormReadOnly, acDialog

End Sub


Is there a different approach to opening reports? Please help
 
If you're just opening the report, use...

DoCmd.OpenReport "Full Timer - Current Month", acViewNormal
 
That didn't work. I tried just that line, but that way instead of opening the report it began to print the report with a dialog box saying "now printing the report xyz to the printer...".
 
nevermind...I was using the wrong property (ViewNormal) :o

also I had to minimize the form...I had typed acReport instead :D
 
I have used:
DoCmd.ShowToolbar "Ribbon", acToolbarNo,

to disable ribbons for non admin users. But I didn't think it through earlier - I just realized I would need print icon to be available to everybody (for the reports). Is there a way to work around the above line of code? Or would I either have all displayed or none?

I know people can always use Ctrl + P but having an icon is better...
 
Why not just put a Command Button for your Users to print from on the Form.
 
I can do that on the form, but is it possible to have the option when one is in print preview of a report (User friendly...)?
 
Hmm, not that I'm aware of... You would need two buttons, one for preview and one for print OR you might want to consider creating your own ribbons.
 
If I do put command buttons on report for print purposes, how can I not print the button too?

I used (on click)

Me.Visible = False
DoCmd.Printout

but it print out the command button too...
 
Not sure exactly where it is, as I haven't got Access up and running, but you are looking for the "Display When" property of the command button.

It should give you options of Always, Print Only, Screen Only.

Code:
The DisplayWhen property uses the following settings.

Setting		Visual Basic	Description
Always		0		(Default) The object appears in Form view and when printed.
Print Only	1		The object is hidden in Form view but appears when printed.
Screen Only	2		The object appears in Form view but not when printed.
 
Last edited:
On a form I use option group buttons with the following options Email, Print, Print Preview and Close Form.

I will supply sample code if requested.
 
You mean print preview of the report that is linked to records on the form?
 
Another question:

DoCmd.Printout straightaway prints out the report. Is there a way to pop up print options before?
 

Users who are viewing this thread

Back
Top Bottom