SQL Rowsource

D

DS

This works when I use it hrough a Query, but when I use it as SQL it
doesn't work.
Thanks
DS

With Forms!CheckPreview2!ListPreview
..RowSource = "SELECT SalesDetails.SalesID, SalesDetails.LineID, " & _
"SalesDetails.ItemID,
IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity) AS EQuantity, " & _
"IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))) AS EName, " & _
"Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") AS Price " & _
"FROM Items INNER JOIN SalesDetails ON Items.ItemID =
SalesDetails.ItemID " & _
"GROUP BY SalesDetails.SalesID, SalesDetails.LineID,
SalesDetails.ItemID, " & _
"IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity),
IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))), " & _
"Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") " & _
"HAVING(((SalesDetails.SalesID) =[Forms]![OrderScreen]![SalesID])) " & _
"ORDER BY SalesDetails.LineID, Items.ItemType;"
..Requery
..ColumnCount = 9
..ColumnWidths = ".2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in"
End With
 
D

Dirk Goldgar

DS said:
This works when I use it hrough a Query, but when I use it as SQL it
doesn't work.
Thanks
DS

With Forms!CheckPreview2!ListPreview
.RowSource = "SELECT SalesDetails.SalesID, SalesDetails.LineID, " & _
"SalesDetails.ItemID,
IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity) AS EQuantity,
" & _ "IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))) AS EName, "
& _ "Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") AS Price " & _
"FROM Items INNER JOIN SalesDetails ON Items.ItemID =
SalesDetails.ItemID " & _
"GROUP BY SalesDetails.SalesID, SalesDetails.LineID,
SalesDetails.ItemID, " & _
"IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity),
IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))), " & _
"Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") " & _
"HAVING(((SalesDetails.SalesID) =[Forms]![OrderScreen]![SalesID])) "
& _ "ORDER BY SalesDetails.LineID, Items.ItemType;"
.Requery
.ColumnCount = 9
.ColumnWidths = ".2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2
in" End With

You should know by now, you have to tell us *in what way* something
"doesn't work." <g>

In what event, on what form, is this code running? If you are running
it on form "OrderScreen", then any event before the Current event will
be too early, since the (presumably bound) control [SalesID] won't have
a value yet.

Note: this line ...

.... is unnecessary, since setting the RowSource propoerty always forces
a requery.
 
D

DS

Dirk said:
This works when I use it hrough a Query, but when I use it as SQL it
doesn't work.
Thanks
DS

With Forms!CheckPreview2!ListPreview
.RowSource = "SELECT SalesDetails.SalesID, SalesDetails.LineID, " & _
"SalesDetails.ItemID,
IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity) AS EQuantity,
" & _ "IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))) AS EName, "
& _ "Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") AS Price " & _
"FROM Items INNER JOIN SalesDetails ON Items.ItemID =
SalesDetails.ItemID " & _
"GROUP BY SalesDetails.SalesID, SalesDetails.LineID,
SalesDetails.ItemID, " & _
"IIf(SalesDetails.Quantity=1,"""",SalesDetails.Quantity),
IIf([Sub]=1,Items.ItemName,IIf([Sub]=2,"" "" &
Items.ItemName,IIf([Sub]=3,"" "" & Items.ItemName))), " & _
"Items.ItemType, SalesDetails.Sub, SalesDetails.Sent,
Format([BasePrice]*[Quantity],""$0.00"") " & _
"HAVING(((SalesDetails.SalesID) =[Forms]![OrderScreen]![SalesID])) "
& _ "ORDER BY SalesDetails.LineID, Items.ItemType;"
.Requery
.ColumnCount = 9
.ColumnWidths = ".2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2 in;.2
in" End With


You should know by now, you have to tell us *in what way* something
"doesn't work." <g>

In what event, on what form, is this code running? If you are running
it on form "OrderScreen", then any event before the Current event will
be too early, since the (presumably bound) control [SalesID] won't have
a value yet.

Note: this line ...



... is unnecessary, since setting the RowSource propoerty always forces
a requery.
Thanks,,,,,Dirk. Right again! It was running to early! And thanks for
that .requery Tip. One less thing for me to type.
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL Woes 4
Sum of SQL Statement 1
SQL Woes 7
If Statement Problem 1
Listbox Align 3
SQL Rowsource 1
Error 2465 setting recordsource to SQL 4

Top