Avatar of G Scott
G Scott
Flag for United States of America

asked on 

Query not working from module.

I have the following query that works perfectly from within a form:
 
DoCmd.RunSQL ("Delete * from tblScheduleCOLORSMAKE")
Dim strSQL As String
strSQL = "INSERT INTO tblScheduleCOLORSMAKE ( press, tool, colorno, Expr2, tstart, matno, qty ) " & vbCrLf & _
"SELECT pressxlsbu.press, pressxlsbu.tool, pressxlsbu.colorno, Mid([colorno],InStrRev([colorno],""-"")+1) AS Expr2, pressxlsbu.tstart, pressxlsbu.matno, Sum(pressxlsbu.qty) AS SumOfqty " & vbCrLf & _
"FROM pressxlsbu " & vbCrLf & _
"GROUP BY pressxlsbu.press, pressxlsbu.tool, pressxlsbu.colorno, Mid([colorno],InStrRev([colorno],""-"")+1), pressxlsbu.tstart, pressxlsbu.matno " & vbCrLf & _
"HAVING (((pressxlsbu.press)=""MLD33"")) " & vbCrLf & _
"ORDER BY pressxlsbu.tstart;"

DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True
DoCmd.OpenForm "frmScheduleListCOLOR", , , "[press] = 'MLD33'", , , False
Forms!frmScheduleListCOLOR!txtPress = "MLD33"

Open in new window


I have moved it back into a module to make it easier to call from different MLD locations, but now it doesn't work and I can't figure out why:

 
Public Function colorQRY(MOLDNUMBER As String)

DoCmd.SetWarnings False

DoCmd.RunSQL ("Delete * from tblScheduleCOLORSMAKE")
Dim strSQL As String
strSQL = "INSERT INTO tblScheduleCOLORSMAKE ( press, tool, colorno, Expr2, tstart, matno, qty ) " & vbCrLf & _
"SELECT pressxlsbu.press, pressxlsbu.tool, pressxlsbu.colorno, Mid([colorno],InStrRev([colorno],""-"")+1) AS Expr2, pressxlsbu.tstart, pressxlsbu.matno, Sum(pressxlsbu.qty) AS SumOfqty " & vbCrLf & _
"FROM pressxlsbu " & vbCrLf & _
"GROUP BY pressxlsbu.press, pressxlsbu.tool, pressxlsbu.colorno, Mid([colorno],InStrRev([colorno],""-"")+1), pressxlsbu.tstart, pressxlsbu.matno " & vbCrLf & _
"HAVING (((pressxlsbu.press)="" & MOLDNUMBER & "")) " & vbCrLf & _
"ORDER BY pressxlsbu.tstart;"

DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True


DoCmd.OpenForm "frmScheduleListCOLOR", , , "[press] = ' & MOLDNUMBER & '", , , False
'DoCmd.OpenReport "qrySchedule", acViewReport, , "[press] = 'MLD11'", , False
Forms!frmScheduleListCOLOR!txtPress = MOLDNUMBER

End Function

Open in new window


I know it's in the actual SQL statement because the table is not getting populated. Any ideas? Thanks for any help you can give me on this.

PS..I am calling it like this:

Call colorQRY("MLD33")

Microsoft Access

Avatar of undefined
Last Comment
mbizup

8/22/2022 - Mon