taverny
asked on
Delete my custom field created when the line is deleted
So far I created some code, of course with the big helps of EE, and I would like to delete my fields from my table if the user either click delete RMA or delete the line Item or change the return item .
1-what Sub should I put my code for each one of those choice
2- what would be the proper code statment to delete for that.
here is one my line that I would like to modify in delete statment.
1-what Sub should I put my code for each one of those choice
2- what would be the proper code statment to delete for that.
here is one my line that I would like to modify in delete statment.
ASKER
ok I am back again on this , so how do I had the code for the popup message that tells me :"are you sure you want to delete this line item " and also the one that says "do you want to delete this record?" for the RMA.
Private Sub Window_BeforeModalDialog(B yVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)
If PromptString = "Do you want to save changes to this cash receipt?" and Answer = dcButton1 Then
'Delete the respective record from my custom table
End If
End Sub
If PromptString = "Do you want to save changes to this cash receipt?" and Answer = dcButton1 Then
'Delete the respective record from my custom table
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just tried the suggestion and it doesn't even go into the sub when I press delete.
this is what I have right now :
Private Sub Window_BeforeModalDialog(B yVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'Delete the respective record from my custom table
Set cn = UserInfoGet.CreateADOConne ction
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete REQUISITION from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
end if
end sub
this is what I have right now :
Private Sub Window_BeforeModalDialog(B
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'Delete the respective record from my custom table
Set cn = UserInfoGet.CreateADOConne
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete REQUISITION from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
end if
end sub
ASKER
Nevermind , I needed to close the RMA entry and reopen it to refresh the code.
now I am troubleshooting it , why it doesn't delete it.
now I am troubleshooting it , why it doesn't delete it.
ASKER
I don't think it would work it seems that it gets into the code before I can even answer delet or cancel.
the sub is called before the messagebox is display.
the sub is called before the messagebox is display.
ASKER
I actually ending doing this instead using the aftermodaldialog.here is the code , let me know if it is ok with you , it seems to work I just need to test it a little , like in case no record exists in the table would it give me an error or it will run and not do anything.
Private Sub Window_AfterModalDialog(By Val DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'Delete the respective record from my custom table
Set cn = UserInfoGet.CreateADOConne ction
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
End If
End Sub
Private Sub Window_AfterModalDialog(By
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'Delete the respective record from my custom table
Set cn = UserInfoGet.CreateADOConne
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
End If
End Sub
ASKER
ok I think I got it now . it seems to delete the RMA line and also the all RMA
'*********
'This sub is to delete the custom field When deleting a Row or deleting an RMA
'*********
Private Sub Window_AfterModalDialog(By Val DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'This will delete all records for the RMA Number on the PSHRMAEXTRA
Set cn = UserInfoGet.CreateADOConne ction
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' "
'and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
End If
If PromptString = "Are you sure you want to delete this line item?" And Answer = dcButton1 Then
'This will delete the line item for the RMA Number and line number on the PSHRMAEXTRA
Set cn = UserInfoGet.CreateADOConne ction
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '" & CStr(CDbl(RMAEntryUpdateDe tail.LineS EQNumber)) & ".00000'"
Set rst = cn.Execute(strsql)
End If
End Sub
'*********
'This sub is to delete the custom field When deleting a Row or deleting an RMA
'*********
Private Sub Window_AfterModalDialog(By
If PromptString = "Do you want to delete this record?" And Answer = dcButton1 Then
'This will delete all records for the RMA Number on the PSHRMAEXTRA
Set cn = UserInfoGet.CreateADOConne
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' "
'and LINESQNUM = '111.00011'"
Set rst = cn.Execute(strsql)
End If
If PromptString = "Are you sure you want to delete this line item?" And Answer = dcButton1 Then
'This will delete the line item for the RMA Number and line number on the PSHRMAEXTRA
Set cn = UserInfoGet.CreateADOConne
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '" & CStr(CDbl(RMAEntryUpdateDe
Set rst = cn.Execute(strsql)
End If
End Sub
ASKER
if you approve it , then I can close the question.
Thanks
Thanks
Yes, you're right, I was mistaken by using BeforeModal.
Your code is okay.
Your code is okay.
ASKER
Thanks. I am closing this one now. I have another Question open that noone seems to answer it . would you like to take a look ?
Thank you
Thank you
For the delete statement, you can either issue a normal SQL DELETE Statement, or you can issue the normal SELECT statement with the RST (Record Set), and then delete the RST.