Option Explicit
Dim Cnn_AP_RPT As ADODB.Connection
Dim sql As String
Sub Create_table_of_2_weeks_logged_Time()
Open_AP_RPT
sql = "drop table logged_time_table"
Cnn_AP_RPT.Execute sql
sql = "select * into logged_time_table from another_logged_time_table "
sql = sql + "where log_entry_dt between '" + Format(DateAdd("ww", -2, Now), "dd mmm yyyy") + "' and '" + Format(Now, "dd mmm yyyy") + "'"
Cnn_AP_RPT.Execute sql
Close_AP_RPT
End Sub
Sub Open_AP_RPT()
Set Cnn_AP_RPT = New ADODB.Connection
Cnn_AP_RPT.Open "dsn=prod ap_rpt;UID=myUserid;PWD=myPassword"
End Sub
Sub Close_AP_RPT()
Cnn_AP_RPT.Close
End Sub
The above example uses reference: Microsoft ActiveX data objects 2.1 Library. It opens the database, executes the sql and closes the db. You can use later versions of the reference.
ADO expects a connection to either an ODBC data store or an OLE DB provider. The default provider is ODBC. If you don’t want to set up the odbc SYSTEM DSN, you can refer to the ODBC driver in your connection string.
My universe connections use OpenClient which I never use outside freehand sql or standard data providers. I don’t even know if I could.
If you read about ADO in the MS knowledgebase, it might clarify things…