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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable a record... 2

Status
Not open for further replies.

mrwendell

Programmer
Aug 22, 2003
43
US
if i have a checkbox that is true...how can i disable the entire record from being edited, if so how?
 
on the after updateproperty for the checkbox put code like this

If me.mycheckbox=0 then
else
With forms!MyForm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
end if

You'll have to adjust the names to your specific form and control names and test this for syntax but it seems logical.
 
okay...not having used your example yet... my initial question would be...your code looks like it will lock all records on my form...records are displayed on a subform and in datasheet view. so there may be record in the subform that can be edited. would your code this work?

(mymainform) (mymainformsub) (records-datasheetview)
 
mrwendell

Very astute. There are two issues with the above solution...
- It disables "edits" for all records retrieved
- Any unbound combo or list boxes or toggle boxes used for searching will fail to work becuase the values for these controls will also be read-only.

My approach is to add a toggle box which is interpretted as True/False. You can also use a boolean "flag" on the records to prevent further editing.

Once you have decided on how to prevent editing / allowing editing, there are two parts to the "trick"...
- Use OnCurrent event procedure
- You code will lock / unlock the controls you want to affect.

Assumption:
tglNoEdit - toggle button on form
Frozen - field on table to freeze a record

Code:
[COLOR=blue]
Private Sub Form_Current()
[/color]
SetScreen

End Sub

[COLOR=blue]
Private Sub tglNoEdit_AfterUpdate()
[/color]
Me.tglNoEdit = Not Me.tglNoEdit 
SetScreen

End Sub

[COLOR=blue]
Private Sub SetScreen()
[/color]
Dim booSetScreen As Boolean

If Me.frozen Then
    Me.tglNoEdit = True
End If

booSetScreen = Me.tglNoEdit 

Me.TextBox02.Locked = booSetScreen
Me.Combobox04.Locked = booSetScreen
Me.ListBox06.Locked = booSetScreen
Me.textBox08.Locked = booSetScreen

Me.SubForm1.Locked = booSetScreen
Me.SubForm2.Locked = booSetScreen

Me.TextBox10.Visible = Not booSetScreen

If booSetScreen Then
    Me.EditRecord.Caption = "View" & vbCrLf & "Only"
    Me.EditRecord.ForeColor = vbBlue
    SetUser
Else
    Me.EditRecord.Caption = "Edit" & vbCrLf & "Record"
    Me.EditRecord.ForeColor = vbRed
End If

End Sub

...So what happens here.
- The SetScreen subrouting locks / unlocks various controls (text boxes, combo boxes, list boxes) and subforms.
- Two conditions can affect the lock / unlock condition. A) the record is "frozen", the control on the form are always set to Locked; B) By toggleing the toggle button.
- Other controls are always left unlocked such as unbound controls (combo boxes for searching for a record or applying filters)
- The SetScreen also changes the caption on the toggle box so the user can visually see the "edit" status.
- The OnCurrent event always checks the current record for the forzen / unfrozen status.

Richard
 
You didn't supply us with much information so I just tried to point you in the right direction.

My suggestion sounds like its not applicable for you. Richards suggestion sounds like its worth a look.

It seems like there should be an easier method but I can't think of one at the moment.
 
The only other thing I can think of is to loop throug all controls and set them. Then go back and unset the ones that should not be. Or perhaps loop through. If there is a ControlSource, set the control. If not (unbound), then leave it alone. You can do this with a loop For CTL in each Ctontrols.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top