Full Version: What is wrong with this code?
UtterAccess Forums > Microsoft® Access > Access Forms
liquidmetal
Hi
need help on this code : can't figure out why the lock record code does not work properly (the x/y record counter is fine) have followed instruction shown in by memebers in other posts. The problem is that the when the lock is applied it locks all other record not just the record in question.
Private Sub Form_Current()
' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone

If Me.NewRecord Then
Me!Text23 = "0/0"
Else
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
End If
'Show the result of the record count in the text box (txtRecordNo)
Me.Text23 = Me.CurrentRecord & "/" & lngCount
Exit Sub

If Not Me.NewRecord Then
Me.LLID.Locked = Me.LR
Me.LLName.Locked = Me.LR
Me.LLAddress.Locked = Me.LR
Me.LLPostCode.Locked = Me.LR
Me.LLTelephone.Locked = Me.LR
Me.LLMobile.Locked = Me.LR
Me.LLFAX.Locked = Me.LR
Me.LLEmail.Locked = Me.LR
Me.LLweb.Locked = Me.LR
Me.fsubLLTasks.Locked = Me.LR
Me.fsubPyamentLog.Locked = Me.LR
Me.fsubProp.Locked = Me.LR
End If
End Sub
Private Sub LR_AfterUpdate()
If Not Me.NewRecord Then
Me.LLID.Locked = Me.LR
Me.LLName.Locked = Me.LR
Me.LLAddress.Locked = Me.LR
Me.LLPostCode.Locked = Me.LR
Me.LLTelephone.Locked = Me.LR
Me.LLMobile.Locked = Me.LR
Me.LLFAX.Locked = Me.LR
Me.LLEmail.Locked = Me.LR
Me.LLweb.Locked = Me.LR
Me.fsubLLTasks.Locked = Me.LR
Me.fsubPyamentLog.Locked = Me.LR
Me.fsubProp.Locked = Me.LR
End If
End Sub
TIA
fkegley
The Locked property applies to the controls on a form, not to the individual values being displayed by the controls. Therefore, changing what is shown in the controls does not, unless you provide for it, reset the Locked property.
liquidmetal
Frank

Thanks for getting back to me. Let me explain :

In a previous DB I managed to use the techinque shown above to lock individual records, ie by clicking the check box LR. I then put the code above in the on click event of the check box and the current event for the form and it worked.

I am doing the same here, except in this db I also have the x/y record counter code in the current event of the form. It is reading this (x/y) code but not the lock record code (LR) for some reason. It however does seem to running the code which is in the click event for the check box and locks the controls for all records, but I want to lock the controls on individual records

I was hoping that you could point out the obvious flaw in the code.

TIA
dannyseager
you should be able to set the locked property like this.
Are you getting any errors? What is actually happening?
liquidmetal
Managed to work it out
just swapped the code posistions in the current event of the form:
Private Sub Form_Current()
If Not Me.NewRecord Then
Me.LLID.Locked = Me.LR
Me.LLName.Locked = Me.LR
Me.LLAddress.Locked = Me.LR
Me.LLPostCode.Locked = Me.LR
Me.LLTelephone.Locked = Me.LR
Me.LLMobile.Locked = Me.LR
Me.LLFAX.Locked = Me.LR
Me.LLEmail.Locked = Me.LR
Me.LLweb.Locked = Me.LR
Me.fsubLLTasks.Locked = Me.LR
Me.fsubPyamentLog.Locked = Me.LR
Me.fsubProp.Locked = Me.LR
End If

' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone

If Me.NewRecord Then
Me!Text23 = "0/0"
Else
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
End If
'Show the result of the record count in the text box (txtRecordNo)
Me.Text23 = Me.CurrentRecord & "/" & lngCount
Exit Sub

End Sub
Private Sub LR_AfterUpdate()
If Not Me.NewRecord Then
Me.LLID.Locked = Me.LR
Me.LLName.Locked = Me.LR
Me.LLAddress.Locked = Me.LR
Me.LLPostCode.Locked = Me.LR
Me.LLTelephone.Locked = Me.LR
Me.LLMobile.Locked = Me.LR
Me.LLFAX.Locked = Me.LR
Me.LLEmail.Locked = Me.LR
Me.LLweb.Locked = Me.LR
Me.fsubLLTasks.Locked = Me.LR
Me.fsubPyamentLog.Locked = Me.LR
Me.fsubProp.Locked = Me.LR
End If
End Sub
This has done the trick. thanks for the help.
liquidmetal
Danny
Thanks for the reply. I have managed to fix the problem but don't know why it wasn't working and would be grateful for an explanation if you have the time.
Odid not get an error report/alarm.
My original code worked but it locked the controls on all records.
I wanted to lock the controls on individual records. I guessed that the LR code in the current event of the form was not running so as an experiment I swapped it with the x/y code and it works! (so does the x/y code) but am baffled why?
Thanks for the help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.