?
Solved

Query not working from module.

Posted on 2011-10-10
5
Medium Priority
?
268 Views
Last Modified: 2013-11-27
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")

0
Comment
Question by:G Scott
  • 4
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36942410
The syntax of your openform statement is wrong:

>> DoCmd.OpenForm "frmScheduleListCOLOR", , , "[press] = ' & MOLDNUMBER & '", , , False

You're  missing a double quote in the criteria before & MOLDNUMBER.  Fixed:

DoCmd.OpenForm "frmScheduleListCOLOR", , , "[press] = '" & MOLDNUMBER & '", , , False
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36942418
Another correction - one more missing double quote.

Try this:

DoCmd.OpenForm "frmScheduleListCOLOR", , , "[press] = '" & MOLDNUMBER & "'", , , False
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 36942449
Also try this corrected SQL:

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;"

0
 
LVL 1

Author Closing Comment

by:G Scott
ID: 36942535
Hey mbizup, that worked great. Whew, I made you work for that one, huh? Those pesky single and double quotes!! Thanks so much for your help.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36942569
Ha!

Yes, you did make me work for it.  Those embedded single quotes are tough to see, especially for old eyes.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question