?
Solved

Opening a Query as Read Only in the On Click Event

Posted on 2005-03-30
16
Medium Priority
?
1,250 Views
Last Modified: 2012-08-14
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
Comment
Question by:billcute
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 13

Assisted Solution

by:lucas911
lucas911 earned 400 total points
ID: 13663943
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13664886
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
 
LVL 27

Assisted Solution

by:jjafferr
jjafferr earned 400 total points
ID: 13665313
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Author Comment

by:billcute
ID: 13666700
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
 
LVL 4

Author Comment

by:billcute
ID: 13666722
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
 
LVL 4

Author Comment

by:billcute
ID: 13667534
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
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 1200 total points
ID: 13667854
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
 
LVL 4

Author Comment

by:billcute
ID: 13668028
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
 
LVL 4

Author Comment

by:billcute
ID: 13685888
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13686051
DoCmd.OpenForm "MyForm", acFormDS
0
 
LVL 4

Author Comment

by:billcute
ID: 13686219
Thank you Shane, I got it working.
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 13686299
Is ther any code to control the "Ctrl + P" (Printing Command)
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13686304
Modify the code I gave you to check if the key code is vbKeyP.
0
 
LVL 4

Author Comment

by:billcute
ID: 13686319
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13686324
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
 
LVL 4

Author Comment

by:billcute
ID: 13686382
Thanks. If you have time please have a look at my new post.

Regards,
Bill
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question