473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Hide buttons when form is open in read only mode

I have a form that I have opened from a button to open in "acFormReadOnly" and i want to hide certain buttons on the form. Is this possible?
Apr 15 '11 #1

✓ answered by TheSmileyCoder

Sorry, but I really have no clue where you want to go with so little information to go on. Which parts of the allready given code does not meet your requirements?

EDIT: Modified code below. I had accidentally chosen .Enabled instead of .Visible. Fixed it:
Expand|Select|Wrap|Line Numbers
  1. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  2.         Me.btnEdit.Visible= True
  3.     Else
  4.         Me.btnEdit.Visible= False
  5. End If

13 5122
TheSmileyCoder
2,322 Expert Mod 2GB
In your forms load event you could have code such as this to achieve what you want:
Expand|Select|Wrap|Line Numbers
  1. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  2.         Me.btnEdit.Enabled = True
  3.     Else
  4.         Me.btnEdit.Enabled = False
  5. End If
Apr 15 '11 #2
thanks a bunch but is there a way to make it more sofisticated (excuse the spelling). for e.g. is it possible to use "Case" for this?
Apr 15 '11 #3
TheSmileyCoder
2,322 Expert Mod 2GB
You need to provide more details on what your thinking. Of course you can use a CASE statement but you dont give any information as to what your selection criteria should be.
Apr 15 '11 #4
what information do i need to state? All i am trying to do is to disable some buttons when i open the form in read only mode
Apr 15 '11 #5
is there any way to convert this intom case?
Apr 23 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Sorry, but I really have no clue where you want to go with so little information to go on. Which parts of the allready given code does not meet your requirements?

EDIT: Modified code below. I had accidentally chosen .Enabled instead of .Visible. Fixed it:
Expand|Select|Wrap|Line Numbers
  1. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  2.         Me.btnEdit.Visible= True
  3.     Else
  4.         Me.btnEdit.Visible= False
  5. End If
Apr 23 '11 #7
this is my code now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. 'if form is NOT opened in read only mode...'
  4. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  5.     'allow 'new sale' button'
  6.     Me.cmdNewSale.Enabled = True
  7. Else
  8.     'if not, disable 'new sale' button'
  9.     Me.cmdNewSale.Enabled = False
  10. End If
  11.  
  12. 'if form is NOT opened in read only mode...'
  13. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  14.     'allow 'add customer' button'
  15.     Me.cmdAddCust.Enabled = True
  16. Else
  17.     'if not, disable 'add customer' button'
  18.     Me.cmdAddCust.Enabled = False
  19. End If
  20.  
  21. 'if form is NOT opened in read only mode...'
  22. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  23.     'allow 'Last navigation' button'
  24.     Me.cmdLast.Visible = False
  25. Else
  26.     'if not, disable 'last navigation' button'
  27.     Me.cmdLast.Visible = True
  28. End If
  29.  
  30. 'if form is NOT opened in read only mode...'
  31. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  32.     'allow 'previous' button'
  33.     Me.cmdPrev.Visible = False
  34. Else
  35.     'if not, disable 'previous' button'
  36.     Me.cmdPrev.Visible = True
  37. End If
  38.  
  39. 'if form is NOT opened in read only mode...'
  40. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  41.     'allow 'next' button'
  42.     Me.cmdNext.Visible = False
  43. Else
  44.     'if not, disable 'previous' button'
  45.     Me.cmdNext.Visible = True
  46. End If
  47.  
  48. 'if form is NOT opened in read only mode...'
  49. If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
  50.     'allow 'First' button'
  51.     Me.cmdFirst.Visible = False
  52. Else
  53.     'if not, disable 'First' button'
  54.     Me.cmdFirst.Visible = True
  55. End If
  56.  
  57. End Sub
  58.  
I was wondering how I can make this into Case instead of if and else.

for example
Expand|Select|Wrap|Line Numbers
  1. select case "when form is in add mode"
  2.  
  3. case me.cmdNewSale.Enabled = True
  4.      me.cmdLast.Visble = False
  5.  
and so on?
Apr 24 '11 #8
NeoPa
32,556 Expert Mod 16PB
Be very careful with big and clumsy code. Especially be careful of comments within it. Your comments don't match the code and are therefore causing more problems in comprehension than they help with. Also, consider simplifying your code which is much clumsier than necessary :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim blnEnabled As Boolean
  3.  
  4. 'if form is NOT opened in read only mode...
  5. blnEnabled = (Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions)
  6.  
  7. 'allow if NOT opened in read only mode
  8. Me.cmdNewSale.Enabled = blnEnabled
  9. Me.cmdAddCust.Enabled = blnEnabled
  10.  
  11. 'allow if IS opened in read only mode
  12. Me.cmdLast.Visible = Not blnEnabled
  13. Me.cmdPrev.Visible = Not blnEnabled
  14. Me.cmdNext.Visible = Not blnEnabled
  15. Me.cmdFirst.Visible = Not blnEnabled
  16.  
  17. End Sub
NB. Comment lines do not require a closing quote (').

Lastly, consider your logic here. Why disable navigation buttons just because the form has not been opened in read only mode?
Apr 25 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
As I see it, SELECT CASE is something you use when you have multiple possible scenarios. In your case, from you have told us thus far, you have 2 options. Read only, and Not Read Only. Thats why I see little sense in using a SELECT CASE.


Regarding your pseudo code:
Expand|Select|Wrap|Line Numbers
  1. select case "when form is in add mode"
There is also no "simply" identifier as to when a form is in read only mode, or add mode. To some extent it depends on your definitions. For example, to some people Read Only means they cannot edit old records but they can add new ones, while to others it means they cannot do anything but read.

True read only (the second case I described) would be:
Expand|Select|Wrap|Line Numbers
  1. Me.AllowAdditions=false
  2. Me.AllowEdits=false
  3. Me.AllowDeletions=false
Personally I have for each of my forms a LockForm procedure which takes a single boolean argument,to either lock/unlock the form. This procedure gets called in the forms load event, and the forms current event, as well as the forms afterUpdate event. (and on click of the edit button).
Apr 26 '11 #10
this is what i have so far but i cant seem to get it to work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim readonly As AcFormOpenDataMode
  4. Dim add As AcFormOpenDataMode
  5. Dim edit As AcFormOpenDataMode
  6.  
  7. Select Case opentype
  8.     Case "readonly"
  9.         readonly = acFormReadOnly
  10.             Me.cmdNewSale.Enabled = False
  11.             Me.cmdAddCust.Enabled = False
  12.             Me.cmdFirst.Visible = True
  13.             Me.cmdPrev.Visible = True
  14.             Me.cmdNext.Visible = True
  15.             Me.cmdLast.Visible = True
  16.     Case "add"
  17.         add = acFormAdd
  18.             Me.cmdNewSale.Enabled = True
  19.             Me.cmdAddCust.Enabled = True
  20.             Me.cmdFirst.Visible = False
  21.             Me.cmdPrev.Visible = False
  22.             Me.cmdNext.Visible = False
  23.             Me.cmdLast.Visible = False
  24.     Case "edit"
  25.         edit = acFormEdit
  26.             Me.cmdNewSale.Enabled = False
  27.             Me.cmdAddCust.Enabled = False
  28.             Me.cmdFirst.Visible = True
  29.             Me.cmdPrev.Visible = True
  30.             Me.cmdNext.Visible = True
  31.             Me.cmdLast.Visible = True
  32.     End Select
  33.  
  34. End Sub
  35.  
May 8 '11 #11
NeoPa
32,556 Expert Mod 16PB
Your code shows no signs of being influenced by any of the many posts added to help you.

If you won't respond to what's been posted what do you expect to happen? That's a bit like asking a doctor for help but deciding not to take the medicine. Your choice of course, but best not complain to the same doctor that you're still unwell ;-)
May 8 '11 #12
ive got it to this now:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim blnEnabled As Boolean
  4. Dim blnDisabled As Boolean
  5.  
  6.  
  7. 'if form is NOT opened in read only mode...
  8. blnEnabled = (Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions)
  9.  
  10. blnDisable = (Not Me.AllowAdditions Or Not Me.AllowEdits Or Not Me.AllowDeletions)
  11.  
  12. Select Case blnEnabled
  13.     Case AddEditDelete
  14.         'allow if NOT opened in read only mode
  15.         Me.cmdNewSale.Enabled = blnEnabled
  16.         Me.cmdAddCust.Enabled = blnEnabled
  17.         Me.cmdLast.Visible = blnDisabled
  18.         Me.cmdPrev.Visible = blnDisabled
  19.         Me.cmdNext.Visible = blnDisabled
  20.         Me.cmdFirst.Visible = blnDisabled
  21.     Case readonly
  22.         Me.cmdNewSale.Enabled = blnDisabled
  23.         Me.cmdAddCust.Enabled = blndisbled
  24.         Me.cmdLast.Visible = blnEnabled
  25.         Me.cmdPrev.Visible = blnEnabled
  26.         Me.cmdNext.Visible = blnEnabled
  27.         Me.cmdFirst.Visible = blnEnabled
  28.  
  29. End Select
  30.  
  31. End Sub
  32.  
May 8 '11 #13
I have finally worked out the code
thank you TheSmileyCode and NeoPa for all of your help.
Would not have been able to do this code without your help

if you wanted to see the code here it is:
(not sure whether the comments are correct but to me it makes sense)

Expand|Select|Wrap|Line Numbers
  1. 'when form is loaded'
  2. Private Sub Form_Load()
  3.  
  4. Dim blnEnabled As Boolean
  5. Dim blnDisabled As Boolean
  6.  
  7. 'blnEnabled is when form is opened with capabilities to add, edit and delete records'
  8. blnEnabled = (Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions)
  9.  
  10. 'blnDisable is when form is opened in read only mode'
  11. blnDisable = (Not Me.AllowAdditions Or Not Me.AllowEdits Or Not Me.AllowDeletions)
  12.  
  13. Select Case blnDisable
  14.     'when form is opened in add/edit mode'
  15.     Case AddEditDelete
  16.         'enable new sale button'
  17.         Me.cmdNewSale.Enabled = blnEnabled
  18.         'enable add customer button'
  19.         Me.cmdAddCust.Enabled = blnEnabled
  20.     'if form is not opened in add/edit mode'
  21.     Case Else
  22.         'use blnEnable to disable  new sale button'
  23.         Me.cmdNewSale.Enabled = blnEnabled
  24.         'use blnEnable to disable  add customer button'
  25.         Me.cmdAddCust.Enabled = blnEnabled
  26.         'use blnDisable to enable navigation buttons'
  27.         Me.cmdLast.Visible = blnDisable
  28.         Me.cmdPrev.Visible = blnDisable
  29.         Me.cmdNext.Visible = blnDisable
  30.         Me.cmdFirst.Visible = blnDisable
  31.  
  32. End Select
  33.  
  34. End Sub
  35.  
May 8 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: P | last post by:
Hi, Access 2002. I use DoCmd.OpenForm attached to command buttons to open one form from another form. All forms are open in dialog mode. When a user tries to open a form already opened from a...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
2
by: zhangyl | last post by:
I use a WebBrowser control to open an office Document in my form , but every time when I open a file, there a dialogbox named "File download" showed asking "Whether you want open or save this...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
2
by: abid gee | last post by:
Please give a kind look on my question. and please comments. I am Using C# as development tool of Dot Net 2.0. I wrote a function read_data() that read data from Serial Port continuously.Till...
2
by: solargovind | last post by:
Hi... Can anybody sugguest my below case..? When i open form either in Form View or Datasheet view, the form should come & stand current record. b'cos My user alter the data in previous record...
3
by: Chris | last post by:
Hi, I'm a bit of a vb.net newbie. I'm building a application in VS2005 that will help manage my business. I've got the form working to a extent. What i want to know is the following: 1. Is...
3
by: DavidB | last post by:
I want to be able to go to a specific record on my form when I open it. The record I want to go to will be dynamic based on the value currently stored in a global variable. The global contains...
2
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, I've got a MAIN form, which I have a series of navigational buttons on. When I open a secondary form from that form, I'd like to be able to HIDE the original form. The reason is, if...
3
by: FreddieIT | last post by:
I have a database that works (worked until this morning) great. I have it running off of Access 2003. What's happening is that my form named Investigation isn't showing any records when I open it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.