Solved

Delete my custom field created when the line is deleted

Posted on 2011-02-19
12
442 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:taverny
  • 8
  • 4
12 Comments
 
LVL 10

Expert Comment

by:Abdulmalek_Hamsho
ID: 34935156
Tracking the Deletion of a Trx or Line is easier than tracking the Save, because there's always a confirmation message before the process starts. So, by tracking the confirmation message and what the user selected in that message (Yes/No) would be the best you can do.

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.
0
 

Author Comment

by:taverny
ID: 34944863
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.
0
 
LVL 10

Expert Comment

by:Abdulmalek_Hamsho
ID: 34947817
Private Sub Window_BeforeModalDialog(ByVal 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
0
 
LVL 10

Accepted Solution

by:
Abdulmalek_Hamsho earned 500 total points
ID: 34947831
I'm sorry, the PromptString above was for the Cash Receipt window, anyway, you need to put the exact string.

Private Sub Window_BeforeModalDialog(ByVal 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
End If
End Sub
0
 

Author Comment

by:taverny
ID: 34954783
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(ByVal 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.CreateADOConnection
        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
0
 

Author Comment

by:taverny
ID: 34954893
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:taverny
ID: 34954920
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.
0
 

Author Comment

by:taverny
ID: 34955075
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(ByVal 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.CreateADOConnection
        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
0
 

Author Comment

by:taverny
ID: 34955304
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(ByVal 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.CreateADOConnection
        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.CreateADOConnection
        cn.DefaultDatabase = UserInfoGet.IntercompanyID
        cmd.ActiveConnection = cn

        strsql = " delete from PSHRMAXTRA where RMANUM = '" & RMANumber & "' and LINESQNUM = '" & CStr(CDbl(RMAEntryUpdateDetail.LineSEQNumber)) & ".00000'"
        Set rst = cn.Execute(strsql)
        End If
End Sub
0
 

Author Comment

by:taverny
ID: 34955305
if you approve it , then I can close the question.
Thanks
0
 
LVL 10

Expert Comment

by:Abdulmalek_Hamsho
ID: 34956015
Yes, you're right, I was mistaken by using BeforeModal.

Your code is okay.
0
 

Author Comment

by:taverny
ID: 34956103
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now