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

Locking records on a subform

Status
Not open for further replies.

matrec

Technical User
Feb 19, 2005
19
CY
I have a main form frmMain and a subform subFrm. On the on-Current event of the subform, I use:
Me.AllowEdits = True
Me.AllowDeletions = True
so that all the records are locked. To unlock, I have created two command buttons, one to unlock the records:
Me.AllowEdits = False
Me.AllowDeletions = False
and the second to lock the records again.
What I do not like, is that, if I unlock a record and do the changes to the fields and then save, the records are locked automatically. So if I want to change many records, I have to keep clicking the "Unlock" button after each save.
Any hints how to unlock once and then lock the records after I finish editing ?
Rgds
 
Hi,

You can make to hidden text box on your form adn then on your code set the value for each textbox when you lock the fom with the "locked" or set the value on this text box when the subform is unlocked with "unlocked".

and the on your code before set the allowedit you have to put
if textbox="locked" then
Me.AllowEdits = True
Me.AllowDeletions = True
else
Me.AllowEdits = False
Me.AllowDeletions = False

endif

hope to be usefull
Ali
 
Instead of a command button, consider using a Toggle control. Advantages are...

- Can act like a command button using the AfterUpdate event
- Can be referenced as True or False
- Can change the caption through code

Putting this toegether...

Create a sub routine that locks / unlocks your fields.
It may actually easier to do this from the main form, but your needs may differ. I usually call this subroutine as SetScreen...

Code:
Private Sub SetScreen()

Dim booSetScreen As Boolean

'Me.EditRecord is name of the toggle box
booSetScreen = Me.EditRecord

Me.YourTextField1.Locked = booSetScreen
Me.YourTextField2.Locked = booSetScreen

'Since this is run from the main form
'you can set the Locked value for the entire subform

Me.YourSubForm.Locked = booSetScreen

'add fields as required
'
'Other will actually loop through the controls
'This approach means less typing, especially for 
'big forms

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

End Sub

And then call the SetScreen where required....

Code:
Private Sub Form_Current()
' Current record

SetScreen

End Sub

Private Sub EditRecord_AfterUpdate()
'Toggle button, after update

SetScreen

End Sub

Works for me.
Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top