From: Lars Brownies on
I have a form that is bound to a hyperlink table. I have a delete button
with which you can delete the particular hyperlink record including the
underlying file.

The function that executes the code, first tries to delete the file. If
that's successful, the hyperlink record is deleted. There could be
situations where the hyperlink record can't be deleted for instance because
it's locked. In that case the function would already have deleted the file,
while the hyperlink record remains there.

Is there a way I could perhaps 'pre-lock' the hyperlink record, so I'm 100%
sure it can be deleted after the file has been deleted? Any other hints?

Thanks,

Lars

From: Hans Up on
Lars Brownies wrote:
> I have a form that is bound to a hyperlink table. I have a delete button
> with which you can delete the particular hyperlink record including the
> underlying file.
>
> The function that executes the code, first tries to delete the file. If
> that's successful, the hyperlink record is deleted. There could be
> situations where the hyperlink record can't be deleted for instance
> because it's locked. In that case the function would already have
> deleted the file, while the hyperlink record remains there.
>
> Is there a way I could perhaps 'pre-lock' the hyperlink record, so I'm
> 100% sure it can be deleted after the file has been deleted? Any other
> hints?

On the Data tab of your form's property sheet, you can set Record Locks
to Edited Record. Then you can try to acquire a lock on the current
record with the form's RecordsetClone before deleting it. That lock
attempt will fail if another user has an edit in progress on the same
record in another copy of your form.

Private Sub cmdDelete_Click()
Dim rst As DAO.Recordset
Dim strMsg As String

On Error GoTo ErrorHandler

Set rst = Me.RecordsetClone
rst.Bookmark = Me.Bookmark

'try to lock current record
rst.Edit 'error 3218 if unable to lock

'If <file delete successful> Then
' rst.Delete
'End If

ExitHere:
Set rst = Nothing
On Error GoTo 0
Exit Sub

ErrorHandler:
Select Case Err.Number
Case 3218
strMsg = "Record locked -> unable to delete."
Case Else
strMsg = "Error " & Err.Number & " (" & Err.Description _
& ") in procedure cmdDelete_Click"
End Select
MsgBox strMsg
GoTo ExitHere

End Sub

I don't know what you have in mind for the "<file delete successful>"
condition. But the part that I supplied seems to work in Access 2003.
From: Lars Brownies on
Excellent! thank you.

Lars

"Hans Up" <hans.updyke(a)nospam.invalid> schreef in bericht
news:OvN#KNe2KHA.4016(a)TK2MSFTNGP05.phx.gbl...
> Lars Brownies wrote:
>> I have a form that is bound to a hyperlink table. I have a delete button
>> with which you can delete the particular hyperlink record including the
>> underlying file.
>>
>> The function that executes the code, first tries to delete the file. If
>> that's successful, the hyperlink record is deleted. There could be
>> situations where the hyperlink record can't be deleted for instance
>> because it's locked. In that case the function would already have deleted
>> the file, while the hyperlink record remains there.
>>
>> Is there a way I could perhaps 'pre-lock' the hyperlink record, so I'm
>> 100% sure it can be deleted after the file has been deleted? Any other
>> hints?
>
> On the Data tab of your form's property sheet, you can set Record Locks to
> Edited Record. Then you can try to acquire a lock on the current record
> with the form's RecordsetClone before deleting it. That lock attempt will
> fail if another user has an edit in progress on the same record in another
> copy of your form.
>
> Private Sub cmdDelete_Click()
> Dim rst As DAO.Recordset
> Dim strMsg As String
>
> On Error GoTo ErrorHandler
>
> Set rst = Me.RecordsetClone
> rst.Bookmark = Me.Bookmark
>
> 'try to lock current record
> rst.Edit 'error 3218 if unable to lock
>
> 'If <file delete successful> Then
> ' rst.Delete
> 'End If
>
> ExitHere:
> Set rst = Nothing
> On Error GoTo 0
> Exit Sub
>
> ErrorHandler:
> Select Case Err.Number
> Case 3218
> strMsg = "Record locked -> unable to delete."
> Case Else
> strMsg = "Error " & Err.Number & " (" & Err.Description _
> & ") in procedure cmdDelete_Click"
> End Select
> MsgBox strMsg
> GoTo ExitHere
>
> End Sub
>
> I don't know what you have in mind for the "<file delete successful>"
> condition. But the part that I supplied seems to work in Access 2003.

From: Hans Up on
Lars Brownies wrote:
> Excellent! thank you.

You're welcome. Glad it worked.

Does your application need to account for users adding, renaming, or
deleting files on disk without performing those operations through your
app? It seems to me the situation could become more challenging than I
first considered.
From: Lars Brownies on
Nope. All those actions are done within the application. Users have a
private app import folder in which they put the file. With a click this file
is transfered to a specific app folder where all app files reside.

Lars

"Hans Up" <hans.updyke(a)nospam.invalid> schreef in bericht
news:eGTT40l2KHA.4752(a)TK2MSFTNGP02.phx.gbl...
> Lars Brownies wrote:
>> Excellent! thank you.
>
> You're welcome. Glad it worked.
>
> Does your application need to account for users adding, renaming, or
> deleting files on disk without performing those operations through your
> app? It seems to me the situation could become more challenging than I
> first considered.