Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent field edits 2

Status
Not open for further replies.

craiogram

MIS
Feb 20, 2004
126
0
0
US
I have a switch board that opens a form for finding a record. The navigation controls work fine. My concern is that once a record is found the user can change any field (perhaps even inadvertainly) and it changes it in the database. Is there a way to prevent any changes but still allow the navigation as well a the copying of any txt field? I tried settin the form property of "allow edit" to no but it did not do it. Aany help is very appreciated! Thank you in advance.
 
Allow edits set to false should do the trick.

Is the for in question a subform?

I would also set allow additions and allow deletions to false.

Have you verified that changes you make are real?

If none of these things work, try setting each field on your form to enabled yes, locked yes. This will allow you to select and copy, but not change.

ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
blorf: I have the same problem as craiogram. The main form responds to 'allow edits' but a child form called by a button on the main form will not respond to 'allow edits = false' no matter how I write it. ??? But, your locked solution does work and so my question is: Do you have a good way of cycling through the text boxes to lock them? I have aproximately 50 boxes spread over 5 tabbed pages in one form. Thanks
 
Sub form eh?

Well, when I want a form with a sub form to prevent edits, I use locked instead.

IE Forms!Myform!MySubform!Locked = true

Maybe that will work for you. It lets the user see and copy stuff from the sub form, but not make changes.

HOpe that helps.

ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
Sorry my bad, form is not a subform, but is called by a cmd btn with code: DoCmd.OpenForm Form2, , , stLinkCriteria
Even with DoCmd.OpenForm Form2, , acReadOnly, stLinkCriteria form2 allows editing. ??????
I tried your code, doesn't work, but locking each textbox will. So I used this code to try to cycle through the text-boxes:

Dim ctl As Control

If Me.ckQAStatus = True Then
If ctl.contoltype = acTextBox Then
For Each ctl In Me.Controls
ctl.Locked = True
Next
End If
End if

or based on something I saw on-line I used this code:

Dim ctl As Control

If Me.ckQAStatus = True Then
For Each crl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox
ctl.Locked = True
End Select
End With
Next
end if
Either way I got a "Run-time error 91, Object variable or With block variable not set" in each case the debug stops on the line containing '.ControlType'.

Am I missing something or do these code snippets not tell the whole story? Any thoughts?
 
I have done similar things, but I opted not to check the control type. I used our old friend, on error resume next to prevent errors with locking the wrong type of records. Example:

Private Sub Form_Current()
On Error Resume Next
For Each Control In Me
Control.Locked = True
Next
End Sub

This seemed to work nicely for me. My code is incomplete of course. I am using the on current event, because I have a logic field that says "No edit this record" or is blank. Based on the value of that field, for each record, it runs the above code, or same code but unlocking everything.


ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
If this is your excact code, I'd recommend using Option Explicit as the second line in every module, and in Tools | Options (in VBE), check the "Require Variable Declaration" option.

In the first case, you're testing the ctl.controltype before it's assigned, in the second, you're looping me.crl but testing the controltype of ctl

You'll find some more looping samples here faq702-5010.

Roy-Vidar
 
Guys:
While I was waiting for an answer I noticed that ctl in the 2nd was crl. I corrected the typo and the code works fine. Thank you. And Roy I did look at 5010 and it is great. Thanks to both of you for your time
 
PS: Roy, I put the suggestions into the module, but when I run the first one (just wanting to clear up loose ends even thought the 2nd works) I still get the same error. In your FAQ 5010 I don't see anywhere where you 'assign' ctl.controltype be fore using it like I did.

Still don't quite 'get-it'
 
[tt]If Me.ckQAStatus = True Then
[highlight]If ctl.contoltype = acTextBox Then[/highlight] ' -> 91
For Each ctl In Me.Controls ' <- assigned/instantiated
ctl.Locked = True
Next
End If
End if[/tt]

You're testing the .controltype before you've started looping. The ctl is declared at the tob, but not instantiated/assigned prior to entering the loop (for each ctl in...)

[tt]If Me.ckQAStatus = True Then
For Each ctl In Me.Controls ' <- assigned/instantiated
[highlight]If ctl.controltype = acTextBox Then[/highlight]
ctl.Locked = True
End If
Next
End if[/tt]

- hope I haven't done the same in the faq;-)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top