Too Few Parameters in Access VBA but works in Query builder

前端 未结 1 493
暖寄归人
暖寄归人 2021-01-26 04:38

I am using the below SQL, it works fine if I run it from query builder but once I have put it in VBA it throws out an error:

Code:

With          


        
相关标签:
1条回答
  • 2021-01-26 05:08

    Form- and report-based parameters are only available in the GUI context (queries run using the GUI, forms, reports, macros and DoCmd.RunSQL). You're probably executing this through CurrentDb, and need to use a querydef instead.

    With CurrentDb.CreateQueryDef("", "SELECT [_tbl_Structure].[User Name], tbl_Genesys_Daily.Field32, [_tbl_Structure].[Supervisor Emp Num], [_tbl_Structure].Supervisor FROM _tbl_Structure RIGHT JOIN tbl_Genesys_Daily ON [_tbl_Structure].[User ID] = tbl_Genesys_Daily.Field5 WHERE ((([_tbl_Structure].Supervisor)=?));")
        .Parameters(0) = [Forms]![frm_Manager_Stats_NEW]![Text279]
        Set rs = .OpenRecordset
    End With
    

    You can learn more about the different types of parameters, and when to use which one, in this answer

    0 讨论(0)
提交回复
热议问题