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

Record Locking Help

Status
Not open for further replies.

anon47

Programmer
Nov 28, 2006
80
US
The code below is supposed to work like this. I have a payment button that is located on a form and when the record is locked I don't want an employee to be able to access the make payment button. It don't work right and help?

Private Sub MakePayments_Click()
If Not Forms!sProjects.Recordset.EOF Then
stDocName = "Payments"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Record Being Edited (Try Later)"
End If
End Sub
 
How are ya anon47 . . .

Not sure how your locking but what you want to do is disable the button if the current record is locked. assuming your using the [blue]Locked property[/blue] of textoxes, in the [blue]On Current[/blue] event of the form:
Code:
[blue]   If Me!TextboxName.Locked Then
      Me!MakePayments.Enabled = False
   Else
      Me!MakePayments.Enabled = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
I tried that and it don't work. I want to have it on the onclick so the employee will get a message to wait but I can get it to work right.
 
anon47 . . .

Before we can continue you have to establish [blue]how your locking records![/blue] . . . and that is?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
I am locking "edited records" with access.
 
anon47 . . .

The problem is determining if a record is locked. Try the following in your button.

Note: [blue]PKname[/blue] is the name of the forms unique primarykey and if its numeric remove the two single quotes [COLOR=red yellow]'[/color] where you see them:
Code:
[blue]   Dim rst As DAO.Recordset
   
On Error GoTo GotErr
   Set rst = Me.RecordsetClone
   rst.FindFirst "[[purple][b][i]PKname[/i][/b][/purple]] = [COLOR=red yellow]'[/color]" & Me![purple][b][i]PKname[/i][/b][/purple] & "[COLOR=red yellow]'[/color]"
   rst.Edit [green]'Test if record is locked![/green]
   
   [green]'If record is locked the error handler takes over
   'else continue with your code[/green]
    DoCmd.OpenForm "Payments", , , stLinkCriteria
    
SeeYa:
   Set rst = Nothing
   Exit Sub
       
GotErr:
   MsgBox "Record Being Edited (Try Later)"
   Resume SeeYa[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
. . . Woops . . . forgot an important line (in [purple]purple[/purple]):
Code:
[blue]   [purple][b]rst.CancelUpdate[/b][/purple]
    DoCmd.OpenForm "Payments", , , stLinkCriteria[/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top