Double Click record in cont. form and delete the record

A

Anne

I am trying to double click the TransID on continuous form and delete that
record.
Can someone help me with the code?
 
D

Dennis

Anne,

Do you not have enough room to put a delete button on the line in your
continuous form? I would strongly suggest you create a visible Delete Button
on the TransID line because that is the window standard. Double clicking on
something to delete it is NOT a window starndard. If I double clicked on
something, I would expect to "Open" the TransID detail. I would never ever
guess that double clicking it would delete it.

Now having stated the above, let me answer your questions. First, I'm
assuming that TransID is a text box control? If that is the case, you can
put the delete code in the double click event of the TransID.

If you don't know what code to write, you can use the system generated code
by creating a Delete Button on the same line on the continous form, then cut
that code and paste it in the double click event of the TransId control item.

If you want, you can create a Delete Button make it transparant and then lay
it over the TransId control. Since it is transparant, the delete button will
not appear it will be there. When people click or double click on the
TransID, the really will be clicking or double clicking on the delete button.



Here is come code that I'm developing, it is not complete but it is a start.

Code at top of form:

Const cintRunCmdCan As Integer = 91 ' Err # for Run
Cmd Cancelled err msg.
Const cintNoUndo As Integer = 2046 ' Err # for No
Undo Available
Const cintCouldNotFindObj As Integer = 3011 ' Err # for MS
Jet could not find object



Private Sub cbDelMem_Click()
On Error GoTo Err_cbDelMem_Click

If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
On Error Resume Next
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
If Err.Number <> 0 And Err.Number <> cintCouldNotFindObj Then
GoTo Err_cbDelMem_Click
End If
End If

Exit_cbDelMem_Click:
Exit Sub

Err_cbDelMem_Click:

' If the Delete Command was cancelled, Access generates a RunCmdCancel
error message.
' We do not want to display this message, so we will not display the
RunCmdCancel message.
'
If Err.Number <> 0 And Err.Number <> cintRunCmdCan Then
Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description,
"cbDelMem_Click")
End If
Resume Exit_cbDelMem_Click

End Sub
 
A

Anne

Dennis, it is a continuous form. What you say about putting a delete button
on the transID line item does not seem right. There are not fixed number of
lines.

I was tryingto grab that record number with the double click event and was
thinking more in the direction of the transID creating a linkfield, like
Dim stLinkCriteria as String
stLinkCriteria ="[TransID]=" & Me.TransID

I cannot write code, I am good a taking someone elses code and applying it
to my needs, but I cannot find a sample.
 
J

John W. Vinson

Dennis, it is a continuous form. What you say about putting a delete button
on the transID line item does not seem right. There are not fixed number of
lines.

If you put a button control on the detail section of the form in design view,
the button will appear on every row that has data, and clicking it will apply
to that row only.
 
A

Anne

I was able to make it work by creating a delete query. I would like to add
“vbyesno†to the msgbox, but it always comes up with an error.

On the main form, I have a linkfield which holds the record number.

In the TransID field of the delete query I put:
[Forms].[1frmPurchases].[linkfield]

I created a delete button on 1frmPurchases and changed it to include the
field in the message back. The message gives me the TransID=### to be deleted.

Private Sub CmdDelete_Click()
On Error GoTo Err_CmdDelete_Click

Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[transID]=" & Me.linkfield

stDocName = "23DeleteUnsplit"
MsgBox ("Are you sure you want to delete " & stLinkCriteria & "")

DoCmd.OpenQuery stDocName, acNormal, acEdit
Me.Ctl1SfmPurchases.Requery

Creating a delete button on every line item on a continuous form was a
little to scary form me. Too many deletes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top