custom deletes

Cereldine

Registered User.
Local time
Today, 10:19
Joined
Aug 4, 2005
Messages
71
hi, im trying to build a more user friendly interface for the deleting of records. I would like to be able to pass a string value (gsecond) based on a persons surname from a form to a global module. The module would carry out the delete and give a user friendly message. The code is working except for the gSecond value not being passed, how do i pass the value? my code is below

Form code

Option Compare Database
Dim gsecond As String

Private Sub Form_AfterDelConfirm(Status As Integer)
after_delete
End Sub

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
before_delete
End Sub

Private Sub Form_Delete(Cancel As Integer)
gsecond = Me!LastName
End Sub


Module code

Option Compare Database


Public Sub before_delete()
Dim message As String
message = " do you wish to delete " & gsecond & " from table?"
If MsgBox(message, vbYesNo, "confirm delete") = vbYes Then
Response = acDataErrContinue
Cancel = False
Else
Cancel = True
End If

End Sub

Public Sub after_delete()
If Status = acDeleteOK Then
MsgBox gsecond & " has been deleted", , "deleted"
Else
MsgBox gsecond & " was not deleted", , "not deleted"
End If
End Sub


I know its something simple, but having one of those days!!
 
Option Compare Database
Dim gsecond As String

Try:

Private Sub Form_AfterDelConfirm(Status As Integer)
after_delete Me!LastName
End Sub

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
before_delete Me!LastName
End Sub

Module code

Option Compare Database


Public Sub before_delete(gsecond as String)
Dim message As String
message = " do you wish to delete " & gsecond & " from table?"
If MsgBox(message, vbYesNo, "confirm delete") = vbYes Then
Response = acDataErrContinue
Cancel = False
Else
Cancel = True
End If

End Sub

Public Sub after_delete(gsecond as String)
If Status = acDeleteOK Then
MsgBox gsecond & " has been deleted", , "deleted"
Else
MsgBox gsecond & " was not deleted", , "not deleted"
End If
End Sub
 
Last edited:
I use the following on a command button:

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
Dim tUser As String

tUser = Format(Me.UserName, ">")

If MsgBox("You are about to delete the User Account for " & Chr(34) & tUser & Chr(34) & ". " & Chr(13) & " Is that correct ?", vbYesNo + vbQuestion, " User Accounts") = vbYes Then

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Me.Requery
Me.List0.Requery
PopUpMsgBox " The Account for the User " & Chr(34) & tUser & Chr(34) & " has been deleted. ", 2, " User Accounts", vbInformation
End If

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
Msgbox Err.Description
Resume Exit_cmdDelete_Click

End Sub
 
I have tried the first piece of advice and it brings up the error "wrong number of arguements or invalid property assignment"

With the second i could use that but it would mean putting same code on all my delete functions. I wanted a generic delete module that could be called from any of the relevant forms and buttons.
 
I have got round my previous proble by using the following code, there are still a few bugs that i need to iron out though

Option Compare Database
Dim gsecond As String
Dim gTable As String

Private Sub Form_AfterDelConfirm(Status As Integer)

after_delete (gsecond)
End Sub

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

Call before_delete(gsecond, gTable)


End Sub

Private Sub Form_Delete(Cancel As Integer)
gsecond = Me!LastName
gTable = Me.Name

End Sub


Module code

Option Compare Database


Public Sub before_delete(gsecond As String, gTable As String)

Dim message As String
message = " do you wish to delete " & gsecond & " from " & gTable & "?"
If MsgBox(message, vbYesNo, "confirm delete") = vbYes Then
Response = acDataErrContinue '' this is supposed to suppress built in dialog but doesnt?
Cancel = False
Else
Cancel = True
End If

End Sub

Public Sub after_delete(gsecond As String)

If Status = acDeleteOK Then
MsgBox gsecond & " has been deleted", , "deleted"
Else
MsgBox gsecond & " was not deleted", , "not deleted"
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom