I need help adding a field to a mySQL Query in Access

rhaas128

Board Regular
Joined
Jul 5, 2013
Messages
84
The field I need to add is Test.DateClosed I've tried messing around and trying to mimick the other SELECT statements to make them include this field, but have not been able to get it to work correctly. I assume it needs to be in both mySQL = statements but not sure how to get it to work correctly...

Here is what I have:

Code:
Dim mySQL As String
mySQL = "SELECT Test.FirstName, Test.LastName, Test.TSOID, Order_Project, myRand INTO LocalTable " & _
        "FROM (SELECT Test.FirstName, Test.LastName, Test.TSOID, Order_Project, rnd(Order_project) AS myRand " & _
        "FROM (SELECT DISTINCT Test.FirstName, Test.LastName, Test.TSOID, IIf(IsNull([ProjectNbr]),[OrderNbr],[ProjectNbr]) AS Order_Project FROM Test)  AS [%$##@_Alias])  AS [%$##@_Alias] " & _
        "ORDER BY myRand;"
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL mySQL
DoCmd.SetWarnings (WarningsOn)
mySQL = "" & _
"SELECT [Order_Project] as [Ticket Number], TSOID, LastName, FirstName " & _
"FROM LocalTable " & _
"WHERE [Order_Project] In " & _
"(SELECT TOP " & tmpIB & " [Order_Project] " & _
" FROM LocalTable AS DTest_aux " & _
" WHERE DTest_aux.TSOID = LocalTable.TSOID ORDER BY myRand) " & _
"ORDER BY TSOID, Order_Project, LastName, FirstName;"
CurrentDb().QueryDefs("Top3").SQL = mySQL
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,221,586
Messages
6,160,645
Members
451,661
Latest member
hamdan17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top