Share via

SQL statement won't run in VBA

Anonymous
2019-02-27T21:49:35+00:00

I have a SQL statement that works fine when I run my query, but inside the VBA, it doesn't run. I don't get any errors, it just skips over this statement and goes right to the next line of code.

 CurrentDb.QueryDefs("make_MBOM").SQL = "SELECT tblDSGLOBAL_DUPS.IM_ITEM_NBR AS Compound, tblDSGLOBAL_DUPS.IM_ITEM_DESC AS Description, qryAMAPS_BOM_16.Component, " & _

        "S07_IMF_OXPIMF.IM_ITEM_DESC AS CompDescription, qryAMAPS_BOM_16.BOMQty AS Qty, S07_IMF_OXPIMF.IM_UNIT_MEAS AS UoM INTO tbl_MBOM " & _

        "FROM (((tblDSGLOBAL_DUPS LEFT JOIN (qryAMAPS_BOM_16 LEFT JOIN S07_IMF_OXPIMF ON qryAMAPS_BOM_16.Component = S07_IMF_OXPIMF.IM_ITEM_NBR) " & _

        "ON tblDSGLOBAL_DUPS.IM_ITEM_NBR = qryAMAPS_BOM_16.Parent) LEFT JOIN ETO_S07_OXP_GPAEXITM ON tblDSGLOBAL_DUPS.IM_ITEM_NBR = ETO_S07_OXP_GPAEXITM.AEXITM_ITEM_NBR) " & _

        "LEFT JOIN REJ_SPECIALCHAR ON tblDSGLOBAL_DUPS.IM_ITEM_NBR = REJ_SPECIALCHAR.IM_ITEM_NBR) LEFT JOIN S07_IMF_OXPIMF AS S07_IMF_OXPIMF_1 ON " & _

        "tblDSGLOBAL_DUPS.IM_ITEM_NBR = S07_IMF_OXPIMF_1.IM_ITEM_NBR " & _

        "WHERE (((qryAMAPS_BOM_16.Component) Is Not Null) AND ((tblDSGLOBAL_DUPS.PLANT)='16') AND ((S07_IMF_OXPIMF_1.IM_ITEM_STATUS) " & _

        "Not Like '4') AND ((ETO_S07_OXP_GPAEXITM.AEXITM_FAMLY_CODE) Not Like 'U') AND ((REJ_SPECIALCHAR.IM_ITEM_NBR) Is Null) AND ((tblDSGLOBAL_DUPS.MAKE_BUY_CODE)='1')) " & _

        "OR (((qryAMAPS_BOM_16.Component) Is Not Null) AND ((tblDSGLOBAL_DUPS.PLANT)='16') AND ((S07_IMF_OXPIMF_1.IM_ITEM_STATUS) Not Like '4') " & _

        "AND ((ETO_S07_OXP_GPAEXITM.AEXITM_FAMLY_CODE) Is Null) AND ((REJ_SPECIALCHAR.IM_ITEM_NBR) Is Null) AND ((tblDSGLOBAL_DUPS.MAKE_BUY_CODE)='1'))"

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2019-02-28T16:20:44+00:00

    I think you're going to have to provide us with the complete procedure, because as I said, what you've provided us with thus far in no way runs a query.

    Also, in this case it is a SELECT query, are you wanting to open the query to display the results? 

    DoCmd.OpenQuery "make_MBOM", acViewNormal

    If it were an Action query (UPDATE, INSERT, DELETE) then you could do

    CurrentDb.Execute "make_MBOM", dbFailOnError

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-02-28T14:43:08+00:00

    I have a button set up and there is more code that is running, after this SQL statement.

    I have other command buttons, where I have done the exact same thing with the SQL statement from a query, and they all run fine. Just not sure what I did in this one, that causes VBA to skip right over it without even giving me an error.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-02-27T22:07:38+00:00

    But where are you running it exactly?

    Your code is to redefine the SQL statement of a query, but in no way does it run it.

    Do you want to run a query or execute a Raw SQL statement?

    Was this answer helpful?

    0 comments No comments