Results 1 to 8 of 8

Thread: Help with deleting an MSAccess file in VB6.0

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Help with deleting an MSAccess file in VB6.0

    I have been searching trying to figure out the syntax for this but it escapes me.
    I am adding records saving and retrieving no proble but how do I delete a record.
    So far all I have seen in the Database using msAccess is the record marked #DELETED but is not really deleted. Here is my code.
    I could really use some help with this
    Thanks

    Code:
     Private Sub cmdDelete_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
    
            Dim rs As New ADODB.Recordset
    
            If MsgBox("Are you sure that you want to Deletet Record?", vbYesNo) = vbYes Then
                rs.Open("DELETE FROM SDID1OrderDetail where OrderNumber = '" & cbstrCurrOrderNumber & "' and OrderLine = " & SDLI, strConn, 2, 2)
                MsgBox("The Quote record has been deleted.")
                'rs.Update()
                rs = Nothing
    
                HoldHighestSDLI = HoldHighestSDLI - 1
                HighestSDLI = HighestSDLI - 1
                If SDLI > 1 Then
                    SDLI = SDLI - 1
                End If
                ScreenUpDate()
                txtDoorA.Text = SDLI
                txtBaseDoorInfo.Text = "DOOR " & SDLI & " Base:"
                txtBaseDoorInfo2.Text = "DOOR " & SDLI & " Base:"
            Else
                Exit Sub
            End If
        End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Help with deleting an MSAccess file in VB6.0

    Are you sure you are using vb6?

    The code looks like it is for vb.net (from the click event)
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Help with deleting an MSAccess file in VB6.0

    Why are you opening a recordset to run a delete query? You are not returning records to the app so you should not be doing that. You write the SQL statement then execute it on the Connection/Command object combination.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Help with deleting an MSAccess file in VB6.0

    Sorry this was a vb6.0 app upgraded to net. I do not want to change the way the DB connections are made and such. So I want to stay with the formats I know a little better.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Help with deleting an MSAccess file in VB6.0

    Quote Originally Posted by Alfarata View Post
    Sorry this was a vb6.0 app upgraded to net. I do not want to change the way the DB connections are made and such. So I want to stay with the formats I know a little better.
    Try something like this... I typed this in notepad so please amend syntax errors if any...

    Code:
    Try
        oConnOleDb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database1.mdb")
        oConnOleDb.Open()
        oCmdOleDb = New OleDbCommand("Delete from SDID1OrderDetail blah blah query",oConnOleDb)
    
    
        If (oCmdOleDb.ExecuteNonQuery > 0) Then
            MsgBox ("The Quote record has been deleted.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message.ToString(), MsgBoxStyle.Information)
    
    Finally
        oConnOleDb.Close()
    End Try
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Help with deleting an MSAccess file in VB6.0

    I keep seeing the references to why are you opening and to use and SQL statement, I guess I can't get the syntax correct I have tried many variations from the searchs but nothing is workig for me.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with deleting an MSAccess file in VB6.0

    Quote Originally Posted by Alfarata View Post
    Sorry this was a vb6.0 app upgraded to net.
    Then don't use VB6 any more...use .NET

    Don't use ADO any more...use ADO.NET

    You are NEVER going to get comfortable in a .NET world if you insist upon walking using VB6 crutches.

    Moved to VB.NET

    I'll get you started. Here is how you would connect to your Access Database
    vb.net Code:
    1. Imports System.Data.OleDb
    2.  
    3. Public Class Form1
    4.  
    5.     Private connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb;"
    6.     Private conn As OleDb.OleDbConnection
    7.  
    8. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         conn = New OleDbConnection(connstring)
    10.         conn.Open()
    11. End Sub
    Last edited by Hack; May 26th, 2010 at 10:49 AM.

  8. #8
    Lively Member
    Join Date
    Dec 2006
    Posts
    81

    Re: Help with deleting an MSAccess file in VB6.0

    hai,

    Try this
    UrConnection. Execute(" Delete * from urTable Where urConditions")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width