By "dynamic" I mean the use of an SQL string in code.
This is my best to date:
I do not use ODBC frequently. Is there a simpler way?
Public Sub Whatever()
Dim q As DAO.QueryDef
With DBEngine(0)
..BeginTrans
On Error GoTo WhateverErr
Set q = .Databases(0).C reateQueryDef(" Trash" & Format(Now(),
"yyyymmddhhnnss "))
With q
..Connect = "ODBC;DRIVER=SQ L SERVER;SERVER=F FDBA-LAPTOP
\SONYLAPTOP;DAT ABASE=DB_51315; Trusted_Connect ion=yes"
..SQL = "SELECT * FROM FFDBATransactio ns WHERE Year([Date]) = 2007 AND
Month([Date]) = 3"
Debug.Print .OpenRecordset( ).Fields("[Date]").Value ' 2007-03-01
End With
End With
WhateverExit:
DBEngine(0).Rol lback
Exit Sub
WhateverErr:
MsgBox Err.Description
Resume WhateverExit
End Sub
This is my best to date:
I do not use ODBC frequently. Is there a simpler way?
Public Sub Whatever()
Dim q As DAO.QueryDef
With DBEngine(0)
..BeginTrans
On Error GoTo WhateverErr
Set q = .Databases(0).C reateQueryDef(" Trash" & Format(Now(),
"yyyymmddhhnnss "))
With q
..Connect = "ODBC;DRIVER=SQ L SERVER;SERVER=F FDBA-LAPTOP
\SONYLAPTOP;DAT ABASE=DB_51315; Trusted_Connect ion=yes"
..SQL = "SELECT * FROM FFDBATransactio ns WHERE Year([Date]) = 2007 AND
Month([Date]) = 3"
Debug.Print .OpenRecordset( ).Fields("[Date]").Value ' 2007-03-01
End With
End With
WhateverExit:
DBEngine(0).Rol lback
Exit Sub
WhateverErr:
MsgBox Err.Description
Resume WhateverExit
End Sub
Comment