Create a query dynamically

后端 未结 3 465

Hi I need to create a query in MSAccess 2003 through code (a.k.a. VB) -- how can I accomplish this?

3条回答
  •  借酒劲吻你
    2020-12-17 10:45

    Dim strSql As String 'as already in example
    Dim qdf As QueryDef 'as already in example
    
    strSql = "SELECT * FROM tblT WHERE ID =" & Forms!Form1!txtID 'as already in example
    
    On Error Resume Next
    'Delete the query if it already exists
    DoCmd.DeleteObject acQuery, "NewQuery"
    
    Set qdf = CurrentDb.CreateQueryDef("NewQuery", strSql) 'as already in example
    DoCmd.OpenQuery qdf.Name 'as already in example
    
    'release memory
    qdf.Close 'i changed qdef to qdf here and below
    Set qdf = Nothing
    

提交回复
热议问题