Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2005, 08:13 AM
Registered User
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to translate a code in DAO to ADO

please can you help me, i want to use the ADO, but i have some problem, can you translate me please that code in ADO

Dim db As DAO.Database, rst As DAO.Recordset
    Dim SQL As String
    Dim date As Date
    ' open the database
    Set db = CurrentDb()
    SQL = "SELECT Max(the_date) FROM time_by_day"
    ' open the recordset
    Set rst = db.OpenRecordset(SQL, dbOpenForwardOnly, dbReadOnly)
    date_a_ajouter = DateAdd("d", 1, DateValue(rst.Fields(0)))
    While DateDiff("d", date_a_ajouter, Now) > 0
        SQL = "INSERT INTO time_by_day (the_date,the_month,the_year,day_of_month,week_of_ year,month_of_year,quarter) VALUES('" & date & "','" & MonthName(Month(date)) & "','" & Year(date) & "','" & Day(date) & "','" & DatePart("ww", date) & "','" & DatePart("m", date_a_ajouter) & "','Q" & DatePart("q", date) & "')"
        db.Execute SQL
        date = DateAdd("d", 1, date)
    Wend

    ' close the Recordset
    rst.Close
 
Old July 6th, 2005, 10:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Why not try an Update query and then just do:

DoCmd.SetWarnings = False
DoCmd.OpenQuery "qryYourUpdateQueryName"
DoCmd.SetWarnings = True




mmcdonal
 
Old July 7th, 2005, 09:19 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Alternatively, you could create the sql statement in the same way you have in your original post and then use it in a RunSQL command...

'-----------------------------
SQL = "INSERT INTO time_by_day (the_date,the_month,the_year,day_of_month,week_of_ year,month_of_year,quarter) VALUES('" & date & "','" & MonthName(Month(date)) & "','" & Year(date) & "','" & Day(date) & "','" & DatePart("ww", date) & "','" & DatePart("m", date_a_ajouter) & "','Q" & DatePart("q", date) & "')"

docmd.runsql(SQL)
'------------------------------

Either way (this way or mmcdonal's), you are not using DAO or ADO.





Similar Threads
Thread Thread Starter Forum Replies Last Post
DAO vs. ADO SerranoG Access VBA 11 December 5th, 2006 01:19 PM
how to convert this DAO connection code to ADO Con ruth26 VB Databases Basics 0 May 11th, 2006 05:15 AM
DAO / ADO? merguvan Access VBA 8 January 18th, 2004 07:39 AM
converting DAO code to ADO Khalifeh Access 25 November 4th, 2003 01:22 PM
How to connect .dbf file with ADO & DAO with code cbpanchal VB How-To 4 July 28th, 2003 10:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.