hi good day, im a beginner of VB using DAO. Right now im doing my first sales system. My problem is I want to delete something from my database. my code is this.

With DTPicker1
Dbase.Execute(Delete * from SalesTable where eDate = ' " & DTPicker1.Value & " ' ")
End With

Unfortunately this code doesn't work. it gives run-time error "3464".
Anybody can help me.

Hi,

Try This :

Dbase.Execute(Delete * from SalesTable where eDate = #" _
& Format(DTPicker1.Value,"dd-mm-yyyy") & "#")

OR

Dbase.Execute(Delete * from SalesTable where eDate = CDate('" _
& Format(DTPicker1.Value,"dd-mm-yyyy") & "')")

Regards
Veena

Hi,

Try This :

Dbase.Execute(Delete * from SalesTable where eDate = #" _
& Format(DTPicker1.Value,"dd-mm-yyyy") & "#")

OR

Dbase.Execute(Delete * from SalesTable where eDate = CDate('" _
& Format(DTPicker1.Value,"dd-mm-yyyy") & "')")

Regards
Veena

thank you veena for your help. it really helps me a lot on my project. if it is ok for you to ask another help about delete?
this is my problem. I have already an existing data on the database. If i were going to view the existing data it will display on the flexgrid. Now, i want to delete some data on the flex grid, unfortunately all having the same ProdCode will be deleted.
How will i going to delete the data on the database with only the highlighted data only found in the flex grid?
This is my code but it doesn't work and my UI.

Private Sub cmdDelete_Click()
Dim i As Integer


With Me.grd
Dbase.Execute ("Delete * from OrderTable where TransCode ='" & .TextMatrix(.Row, 0) & "'")
End With

With Me.grd
Dbase.Execute ("Delete * from PaymentTable where TransCode ='" & .TextMatrix(.Row, 0) & "'")
End With

With Me.grd
i = .Row
If i > 0 Then
While i < .Rows
If i < .Rows - 1 Then
.TextMatrix(i, 0) = .TextMatrix(i + 1, 0)
.TextMatrix(i, 1) = .TextMatrix(i + 1, 1)
.TextMatrix(i, 2) = .TextMatrix(i + 1, 2)
.TextMatrix(i, 3) = .TextMatrix(i + 1, 3)
.TextMatrix(i, 4) = .TextMatrix(i + 1, 4)
.TextMatrix(i, 5) = .TextMatrix(i + 1, 5)
i = i + 1
Else
.Rows = .Rows - 1
End If
Wend
End If
End With

OT.MoveFirst
Do Until OT.EOF
With OT
.Edit
!Amount = lblGrnTotal.Caption
.Update
End With
OT.MoveNext
Loop

PAY.MoveFirst
Do Until PAY.EOF
With PAY
.Edit
!Amount = lblGrnTotal.Caption
.Update
End With
PAY.MoveNext
Loop

Load Form16
Form16.Show
End Sub


regards;
Denine:icon_question:

Attachments or2.JPG 65.61 KB

Hi,

You need 2 Conditions in The Delete Statement :

"Delete * from OrderTable where ProdCode ='" & .TextMatrix(.Row, 0) & "' And TransCode=" Val(txtTransNo.Text)

If ProdCode Is Numeric, then Remove the Single Quotes..
After Deleting From Database, you need to Remove the Row From the Grid As well...
:

If Grd.Row > 0 Then
    Grd.RemoveItem Grd.Row
End If

Regards
Veena

Hi Veena once again thank you so much for your help. The code that you gave me works on my project. Here's another problem on my code, I hope you can still help me. It is all about in my counter and in my total sales.
The Code of my counter that I make doesn't work again and also in displaying the total sales in descending order. This is my code.


-----------------------------------------------------------------
counter

For i = 1 To grd.Rows - 1
With INV
If grd.TextMatrix(i, 0) = INV!ProdCode Then
.Edit
!Quantity = !Quantity + Val(grd.TextMatrix(i, 3))
.Update
Else
.AddNew
!ProdCode = grd.TextMatrix(i, 0)
!ProdName = grd.TextMatrix(i, 2)
!Quantity = grd.TextMatrix(i, 3)
!Date = DTPicker1.Value
.Update
End If
End With
Next i

---------------------------------------------------------------------------------------
Display the Total Sale in descending order

Set SH = Dbase.OpenRecordset("Select * from SalesHeader where iDate <= cDate (' " & CStr(DTPicker1.Value) & " ') and iDate >= cDate(' " & CStr(DTPicker2.Value) & " ')Order by cDate Desc ")

----------------------------------------------------------------------------


Regards

Denine

hi, am fred
am designing a simple program of telephone directory using vb6.0, i would like to get a code
that deletes all the contents in the database. help me please am stuck. I have tried the one below and it refused, it only deletes one record in the database. thanks.

Private Sub Command2_Click()
Dim imessage As Integer
imessage = MsgBox(" are you sure you want to delete this record?", vbYesNoCancel + vbQuestion)
If imessage = vbYes Then
Data1.Recordset.Delete
Data1.Recordset.MoveNext
End If

This article has been dead for over six months. Start a new discussion instead.