Results 1 to 2 of 2
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Code Need To Be Fixed To Delete Field Instead Of Row

    Hi am trying to delete only a field "MasterSR" from "Purchases" But when I execute the code it deletes the whole row.
    Where as I only want "MasterSR" from "Purchases" table to delete or make it null.


    Following is the code, how can I fix this.






    Private Sub cboDeleteGPass_AfterUpdate()
    On Error GoTo Error_Handler
    Dim sSQL As String
    Dim pSQL As String
    If MsgBox("DELETE All Salary Voucher Records With Voucher Number = " & Me.cboDeleteGPass & "?", vbQuestion + vbYesNo, " C O N F I R M ") = vbNo Then Exit Sub
    sSQL = "DELETE * FROM MonSlryVchrTbl WHERE GPPurNumbr = " & Me.cboDeleteGPass
    pSQL = "DELETE * FROM Purchases WHERE MasterSR = " & Me.cboDeleteGPass


    'Debug.Print sSQL
    CurrentDb.Execute sSQL, dbFailOnError
    CurrentDb.Execute pSQL, dbFailOnError
    CurrentDb.TableDefs.Refresh
    Me.cboDeleteGPass.Requery
    Me.cboDeleteGPass = ""


    Error_Handler_Exit:
    On Error Resume Next
    Exit Sub
    Error_Handler:
    Select Case Err
    Case Else
    MsgBox "Error " & Err.Number & " (" & Err.Description & ")", vbExclamation, "Error in Sub cboDeleteGPass_AfterUpdate of Form_MonSlryVchrFrm"
    End Select
    Resume Error_Handler_Exit
    Resume
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Use ALTER TABLE DROP COLUMN action SQL or TableDefs to modify table. This will delete field from table and data is gone.

    Programmatically modifying db structure is usually bad idea and indicative of poor design.

    Use UPDATE action SQL to set field to NULL for specific record(s).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 12-30-2020, 08:20 PM
  2. Replies: 1
    Last Post: 12-10-2017, 01:47 AM
  3. Replies: 7
    Last Post: 09-16-2017, 04:01 PM
  4. Fixed character length of field
    By tylerg11 in forum Access
    Replies: 3
    Last Post: 09-29-2011, 11:58 AM
  5. Convert number to fixed length text field
    By tpcervelo in forum Queries
    Replies: 1
    Last Post: 08-02-2010, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums