Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1257
  • Last Modified:

Opening a Query as Read Only in the On Click Event

I currently have a query that I normally  open from an On Click Event of a "form". I now want to modify the "On Click Event
of the " the query to open as "Read Only" such that when the query view is launched, ALL "MENU" and "Tools / Shortcut" for "COPYING", "PASTING" and "PRINTING" should be "locked or invinsible" as well.

The DB itself has been converted to MDE with all "Tools" disabled in the "StartUp" but with this command button below,  the "Menu" and "tools" like,  the "Copy & Paste / Print" are enabled.
I want them disabled. Any suggestion will be appreciated.

I am open to other suggestions. I have locked

Private Sub btnOpenQuery_Click()

On Error GoTo Err_btnOpenQuery_Click

    Dim stDocName As String

    stDocName = "qryWaterPermits"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_btnOpenQuery_Click:
    Exit Sub

Err_btnOpenQuery_Click:
    MsgBox Err.Description
    Resume Exit_btnOpenQuery_Click
   
End Sub
0
billcute
Asked:
billcute
3 Solutions
 
LucasMS Dynamics DeveloperCommented:
Just change the way you open the query:

DoCmd.OpenQuery stDocName, acNormal, acReadOnly

That way the query will always be READ ONLY no matter what.
0
 
shanesuebsahakarnCommented:
Do not use a query for direct input or viewing. You have no control over toolbars when using a query, and you cannot prevent the user from copying with CTRL+C. Use a datasheet form instead and place code or change the form properties so that the toolbar is not provided and/or the copy button combination is trapped for.
0
 
jjafferrCommented:
Hi Bill

I would suggest Making a Datasheet Form, this will make it look as if it is a query,
and make this Query as the Record Source for the Form,
Now in the Form, you can set AllowEdit, AllowDelete, AllowAddition, set them all to NO,
Like Shane said, you don't have control over queries, but with the Form, you have total control.

I hope this helps,

jaffer
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
billcuteAuthor Commented:
Shane / Jaffer,
I understand your points to a degere. But I will appreciate it if Shane could explain "how to" do configure the form !!!

Shane wrote:
".....and place code or change the form properties so that:

---> the "toolbar" is not provided and/or the "copy button" combination is trapped for.

Shane, Would you mind providing an example of what code to place to grey out the COPY / PASTE and "Print" commands ?

Cheers
Bill
0
 
billcuteAuthor Commented:
lucas911
Your example is quite good and useful as well but I'll probably agree with the last two experts due to the flexibility in controlling forms but  I dont quite have the "grip" on how to place codesto "ock out"certain commands as suggested as by Shane.

Thanks for your assistance.
Bill
0
 
billcuteAuthor Commented:
To All,
It will be appreciated if someone can provide further explanation to:

Shane note below:
".....and place code or change the form properties so that:

---> the "toolbar" is not provided and/or the "copy button" combination is trapped for.
0
 
shanesuebsahakarnCommented:
You would just design a toolbar that doesn't have the Copy/Paste buttons and set the form to use that toolbar instead of the default one (by setting its MenuBar property).

As for the second, set the form's KeyPreview property to Yes and use code like this in the  form's KeyDown event:
If KeyCode=vbKeyC And (Shift Or 2)=2 Then
   MsgBox "Copying not allowed."
   KeyCode=0
End If
0
 
billcuteAuthor Commented:
Thanks Shane,
I accept your answer whole heartedly but I will like to show my appreciation to other experts as well for their contribution. The ratio of the split will be 3-1-1 with you having the most.

Bill
0
 
billcuteAuthor Commented:
To All,
I have tried all the suggestions for this post but I cant get the "datasheet" form I created to open in a datasheet format.

When I click the code below, the form opens as a single form even though the is designed as "datasheet".
But when I click the form in the object window it opens as a datasheet.

I believe that my DoCmd.OpenForm may be faulty. can someone assist with this code ?  <--------------

Private Sub btnOpenTable_Click()

On Error GoTo Err_btnOpenTable_Click

    Dim stDocName As String

    stDocName = "frmFormTable"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_btnOpenTable_Click:
    Exit Sub

Err_btnOpenTable_Click:
    MsgBox Err.Description
    Resume Exit_btnOpenTable_Click
   
End Sub

I have alsso created a new post to address Shane's :MENU" suggestion at the link below:
http://www.experts-exchange.com/Databases/MS_Access/Q_21373657.html
0
 
shanesuebsahakarnCommented:
DoCmd.OpenForm "MyForm", acFormDS
0
 
billcuteAuthor Commented:
Thank you Shane, I got it working.
Bill
0
 
billcuteAuthor Commented:
Is ther any code to control the "Ctrl + P" (Printing Command)
0
 
shanesuebsahakarnCommented:
Modify the code I gave you to check if the key code is vbKeyP.
0
 
billcuteAuthor Commented:
Is it like this or must it be modified further? Where will I place the code this time? How about Key Preview settings?

If KeyCode=vbKeyP And (Shift Or 2)=2 Then
   MsgBox "Copying not allowed."
   KeyCode=0
End If
0
 
shanesuebsahakarnCommented:
That code is correct. It should be placed in the same event procedure as before. The Key Preview setting remains the same as for the other code.
0
 
billcuteAuthor Commented:
Thanks. If you have time please have a look at my new post.

Regards,
Bill
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now