I have draw a Calendar on the form. After selecting the date, month and year, how do i add the record to the database using DAO and also ADO?? Help is really appreciated.
Printable View
I have draw a Calendar on the form. After selecting the date, month and year, how do i add the record to the database using DAO and also ADO?? Help is really appreciated.
The usual way ;)
DAO:
VB Code:
Dim db as Database Dim rst as Recordset On Error Resume Next Set db = DBEngine(0).OpenDatabase("C:\Test.Mdb",False,False) Set rst = db.OpenRecordset("Select * from tblTest") If Err.Number=0 Then rst.Addnew rst("DateField") = cdate(MSCal.Value) rst.Update rst.Close End If db.Close Set rst = Nothing Set db = Nothing
ADO:
VB Code:
Dim adoCon as New ADODB.Connection Dim adoRst as New ADODB.Recordset On Error Resume Next adoCon.Open <Connection String here> adoRst.CommandString adoRst.Open ,adoCon,<options>,<options>,adCmdText If adoCon.State=adStateOpen Then If adoRst.State=adStateOpen Then adorst.Addnew adorst("DateField") = cdate(MSCal.Value) adorst.Update adorst.Close End If adoCon.Close End If Set adoRst = Nothing Set adoCon = Nothing
NOTE This is from memory (ADO) and if you are using Access for coding the top should work right. If in VB then you may need to tweak the coding a little.
Regards
Vince
PS : If anyone can give the correct connections string and adorst property... Please do.
PPS : Or if anyone knows a site with all the connection string examples in on one page... Definately please do.