Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Delete item in database based on date field not working


Delete item in database based on date field not working

Author
Message
Raycomp
Raycomp
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 20, Visits: 58
I hope someone here might have the answer





I have a form from where I would like to delete all records before a specified date, the form has a text field and command button that should delete records in the database older than 3 months but it does not delete the records.



the code on my form is as follows







Private Sub Form_Load()

Dim test As String



test = DateAdd("m", -3, Now) 'this uses the current date and subtract 3 months

Text1.Text = test

Text1.Text = Format$(test, "mm/dd/yyyy")



End Sub





Private Sub Command1_Click()



Dim cs As New ADODB.Connection

Dim rec As New ADODB.Recordset

Dim flds As New ADODB.Recordset



cs.ConnectionString = "Provider =Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=" & "C:\Program Files\Hazmat Control\HazMat.mdb"

cs.Open



Dim date1 As String

cs.BeginTrans

cs.Execute "DELETE * From ControlDetailsA where Date <= " & Text1.Text 'date is the field in the access table

cs.CommitTrans



End Sub




If I however change the code to delete by control number then it is successful. Looks like I am missing something when trying to use the date field to select the records.

Edited
10/25/2014 by Raycomp
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search