Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-26-2018, 10:13 PM   #1
Gismo
Newly Registered User
 
Join Date: Jun 2017
Posts: 329
Thanks: 204
Thanked 1 Time in 1 Post
Gismo is on a distinguished road
Close form if no data

Hi All,

I have a button to open a form, then go to a new record. If you do not have access to open the form it pops up a message then closes the form. It does close the form but then gives message that the form is not open when the user does not have access to open the form.
Below my code, ho do I overcome this message?

Code:
Private Sub Form_Load()
Dim Msg As VbMsgBoxResult

 If Me.Recordset.RecordCount = 0 Then
  MsgBox "You do not have access to the User Menu."
  DoCmd.Close
  End If
End Sub

Gismo is offline   Reply With Quote
Old 08-27-2018, 01:17 AM   #2
bob fitz
AWF VIP
 
Join Date: May 2011
Location: Essex England
Posts: 3,505
Thanks: 50
Thanked 679 Times in 662 Posts
bob fitz has a spectacular aura about bob fitz has a spectacular aura about bob fitz has a spectacular aura about
Re: Close form if no data

I you delete the line of code:
Code:
MsgBox "You do not have access to the User Menu."
then the message box will not be shown.
__________________
Bob Fitzpatrick
Microsoft Community Contributor Award (2011)
If this helped, please click the scales at the bottom left of this posting.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Many thanks.


I have never failed. I have found a thousand ways that do not work!
bob fitz is online now   Reply With Quote
Old 08-27-2018, 01:27 AM   #3
Gismo
Newly Registered User
 
Join Date: Jun 2017
Posts: 329
Thanks: 204
Thanked 1 Time in 1 Post
Gismo is on a distinguished road
Re: Close form if no data

I need to show the message if no access is granted but the problem is the message that the form is not open when I go to a new record when access is permissible.

Gismo is offline   Reply With Quote
Old 08-27-2018, 01:38 AM   #4
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,110
Thanks: 421
Thanked 753 Times in 731 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Close form if no data

I would not be giving them the chance to open the form in the first place?
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 08-27-2018, 01:49 AM   #5
bob fitz
AWF VIP
 
Join Date: May 2011
Location: Essex England
Posts: 3,505
Thanks: 50
Thanked 679 Times in 662 Posts
bob fitz has a spectacular aura about bob fitz has a spectacular aura about bob fitz has a spectacular aura about
Re: Close form if no data

Quote:
Originally Posted by Gismo View Post
I need to show the message if no access is granted but the problem is the message that the form is not open when I go to a new record when access is permissible.
The code you have tests for existing records, not for a users permission status.

I agree with Gasman's comment that it would be better to determine the users permission status before opening the form.
__________________
Bob Fitzpatrick
Microsoft Community Contributor Award (2011)
If this helped, please click the scales at the bottom left of this posting.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Many thanks.


I have never failed. I have found a thousand ways that do not work!
bob fitz is online now   Reply With Quote
Old 08-27-2018, 01:51 AM   #6
Gismo
Newly Registered User
 
Join Date: Jun 2017
Posts: 329
Thanks: 204
Thanked 1 Time in 1 Post
Gismo is on a distinguished road
Re: Close form if no data

Yes I agree, not to sure how to test for permission before the form opens.
I need to give the admin user access to add or change user access.

Could you please advise on a code to test for access before the form opens?
Gismo is offline   Reply With Quote
Old 08-27-2018, 01:57 AM   #7
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,110
Thanks: 421
Thanked 753 Times in 731 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Close form if no data

Use whatever you test with now. Hide the button if not allowed to access.

The way I have done it in one of my DBs is to check the user access as they log in, and store it in a TempVar for the use of the session. A global variable would work just as well, or even a class (which is way beyond my skill level )

Saves having to check it each time.
The user access levels are in a table as I would expect yours are.?


__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
Gismo (08-27-2018)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Form changes data Richard1941 Forms 7 02-15-2013 05:39 PM
requested enter data when close a data add form newaccess Forms 1 01-11-2013 05:41 AM
Close Form on no Data hullstorage General 1 06-17-2009 08:58 AM
form takes an age to close after new data steve-oc Forms 2 11-18-2004 08:16 AM
Close sub form on no data Malcy Forms 6 05-28-2003 07:59 AM




All times are GMT -8. The time now is 04:04 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World