Results 1 to 2 of 2

Thread: Adding Record using MS Calendar Control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    77

    Adding Record using MS Calendar Control

    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.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Hi

    The usual way


    DAO:
    VB Code:
    1. Dim db as Database
    2. Dim rst as Recordset
    3.  
    4. On Error Resume Next
    5.  
    6. Set db = DBEngine(0).OpenDatabase("C:\Test.Mdb",False,False)
    7. Set rst = db.OpenRecordset("Select * from tblTest")
    8.  
    9. If Err.Number=0 Then
    10.  rst.Addnew
    11.  rst("DateField") = cdate(MSCal.Value)
    12.  rst.Update
    13.  rst.Close
    14. End If
    15. db.Close
    16.  
    17. Set rst = Nothing
    18. Set db = Nothing

    ADO:
    VB Code:
    1. Dim adoCon as New ADODB.Connection
    2. Dim adoRst as New ADODB.Recordset
    3.  
    4. On Error Resume Next
    5.  
    6. adoCon.Open <Connection String here>
    7. adoRst.CommandString
    8. adoRst.Open ,adoCon,<options>,<options>,adCmdText
    9.  
    10. If adoCon.State=adStateOpen Then
    11.  If adoRst.State=adStateOpen Then
    12.   adorst.Addnew
    13.   adorst("DateField") = cdate(MSCal.Value)
    14.   adorst.Update
    15.   adorst.Close
    16.  End If
    17.  adoCon.Close
    18. End If
    19.  
    20. Set adoRst = Nothing
    21. 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.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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