H
heidi
Hello All:
I am struggling getting the correct syntax.
Here is what I have:
THIS WORKS!
Main form with a a list box.
LISTBLOCKSELECTION List box is populated by
qryRecommendationsBlockListBox on the afterupdate of
comboranchselection combo box on my main form and txtConventionalCheck
text box is null or not null.
Afterupdate code: me.LISTBLOCKSELECTION.requery
THIS WORKS!
LISTBLOCKSELECTION List box repopulated by
qryRecommendationsBlockListBox on the afterupdate of second combocrop
combo box on my main form.
Afterupdate code: me.LISTBLOCKSELECTION.requery
WON'T WORK!
Have command buttons above my list box to sort the columns Asc or Desc
order based on the already filtered results.
Here is the code behind one sort button.
Private Sub CMDCOMMODITYASC_Click()
'Set commodity order in ascending order and apply captions
Dim response As Integer
response = basOrderby("[COMMODITY]", "ASC")
Me!CMDCOMMODITYDESC.Visible = True
Me!CMDCOMMODITYDESC.Caption = "COMMODITY"
Me!CMDCOMMODITYDESC.SetFocus
Me!CMDCOMMODITYASC.Visible = False
Me!LISTBLOCKSELECTION.SetFocus
End Sub
When using the basOrderBy code, I can not get the multiple WHERE
clause correct to reset the listbox's recordsource.
Here is the basOrderby code:
Private Function basOrderby(col As String, xorder As String) As
Integer
Dim strSQL As String
'Set row source for list box
strSQL = "SELECT DISTINCTROW [LOTNUMBER],[COMMODITY], [BLOCKNAME],
[VARIETY], [SUMOFACRES],[STATUS],[STATUSCHECK]"
strSQL = strSQL & "FROM [qryRecommendationsBlockListBox] "
strSQL = strSQL & "WHERE [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop] AND [STATUSCHECK]=[forms]!
[frmRecommendationsEntry]![txtConventional] OR [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [STATUSCHECK]=[forms]!
[frmRecommendationsEntry]![txtConventional] AND isnull([COMMODITY]=
[forms]![frmRecommendationsEntry]![combocrop]) OR [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop]) AND isnull([STATUSCHECK]=
[forms]![frmRecommendationsEntry]![txtConventional]) OR [LOTNUMBER]=
[forms]![frmRecommendationsEntry]![lotnumber] AND ([COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop]) Is Null)) AND isnull
([STATUSCHECK]=[forms]![frmRecommendationsEntry]![txtConventional]) "
strSQL = strSQL & "ORDER BY " & col & " " & xorder
Me!LISTBLOCKSELECTION.RowSource = strSQL
Me!LISTBLOCKSELECTION.Requery
End Function
Below is the SQL from my underlying query:
SELECT qryRecommendationsBlockListBox.LotNumber,
qryRecommendationsBlockListBox.Commodity,
qryRecommendationsBlockListBox.BlockName,
qryRecommendationsBlockListBox.Variety,
qryRecommendationsBlockListBox.sumOfAcres,
qryRecommendationsBlockListBox.Status,
qryRecommendationsBlockListBox.StatusCheck
FROM qryRecommendationsBlockListBox
WHERE (((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.Commodity)=[forms]!
[frmRecommendationsEntry]![combocrop]) AND
((qryRecommendationsBlockListBox.StatusCheck)=[forms]!
[frmRecommendationsEntry]![txtConventional])) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.StatusCheck)=[forms]!
[frmRecommendationsEntry]![txtConventional]) AND (([forms]!
[frmRecommendationsEntry]![combocrop]) Is Null)) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.Commodity)=[forms]!
[frmRecommendationsEntry]![combocrop]) AND (([forms]!
[frmRecommendationsEntry]![txtConventional]) Is Null)) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND (([forms]!
[frmRecommendationsEntry]![combocrop]) Is Null) AND (([forms]!
[frmRecommendationsEntry]![txtConventional]) Is Null))
ORDER BY qryRecommendationsBlockListBox.BlockName,
qryRecommendationsBlockListBox.Variety;
PLEASE HELP
What am I typing incorrectly. I can't find it.
Heidi
I am struggling getting the correct syntax.
Here is what I have:
THIS WORKS!
Main form with a a list box.
LISTBLOCKSELECTION List box is populated by
qryRecommendationsBlockListBox on the afterupdate of
comboranchselection combo box on my main form and txtConventionalCheck
text box is null or not null.
Afterupdate code: me.LISTBLOCKSELECTION.requery
THIS WORKS!
LISTBLOCKSELECTION List box repopulated by
qryRecommendationsBlockListBox on the afterupdate of second combocrop
combo box on my main form.
Afterupdate code: me.LISTBLOCKSELECTION.requery
WON'T WORK!
Have command buttons above my list box to sort the columns Asc or Desc
order based on the already filtered results.
Here is the code behind one sort button.
Private Sub CMDCOMMODITYASC_Click()
'Set commodity order in ascending order and apply captions
Dim response As Integer
response = basOrderby("[COMMODITY]", "ASC")
Me!CMDCOMMODITYDESC.Visible = True
Me!CMDCOMMODITYDESC.Caption = "COMMODITY"
Me!CMDCOMMODITYDESC.SetFocus
Me!CMDCOMMODITYASC.Visible = False
Me!LISTBLOCKSELECTION.SetFocus
End Sub
When using the basOrderBy code, I can not get the multiple WHERE
clause correct to reset the listbox's recordsource.
Here is the basOrderby code:
Private Function basOrderby(col As String, xorder As String) As
Integer
Dim strSQL As String
'Set row source for list box
strSQL = "SELECT DISTINCTROW [LOTNUMBER],[COMMODITY], [BLOCKNAME],
[VARIETY], [SUMOFACRES],[STATUS],[STATUSCHECK]"
strSQL = strSQL & "FROM [qryRecommendationsBlockListBox] "
strSQL = strSQL & "WHERE [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop] AND [STATUSCHECK]=[forms]!
[frmRecommendationsEntry]![txtConventional] OR [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [STATUSCHECK]=[forms]!
[frmRecommendationsEntry]![txtConventional] AND isnull([COMMODITY]=
[forms]![frmRecommendationsEntry]![combocrop]) OR [LOTNUMBER]=[forms]!
[frmRecommendationsEntry]![lotnumber] AND [COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop]) AND isnull([STATUSCHECK]=
[forms]![frmRecommendationsEntry]![txtConventional]) OR [LOTNUMBER]=
[forms]![frmRecommendationsEntry]![lotnumber] AND ([COMMODITY]=[forms]!
[frmRecommendationsEntry]![combocrop]) Is Null)) AND isnull
([STATUSCHECK]=[forms]![frmRecommendationsEntry]![txtConventional]) "
strSQL = strSQL & "ORDER BY " & col & " " & xorder
Me!LISTBLOCKSELECTION.RowSource = strSQL
Me!LISTBLOCKSELECTION.Requery
End Function
Below is the SQL from my underlying query:
SELECT qryRecommendationsBlockListBox.LotNumber,
qryRecommendationsBlockListBox.Commodity,
qryRecommendationsBlockListBox.BlockName,
qryRecommendationsBlockListBox.Variety,
qryRecommendationsBlockListBox.sumOfAcres,
qryRecommendationsBlockListBox.Status,
qryRecommendationsBlockListBox.StatusCheck
FROM qryRecommendationsBlockListBox
WHERE (((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.Commodity)=[forms]!
[frmRecommendationsEntry]![combocrop]) AND
((qryRecommendationsBlockListBox.StatusCheck)=[forms]!
[frmRecommendationsEntry]![txtConventional])) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.StatusCheck)=[forms]!
[frmRecommendationsEntry]![txtConventional]) AND (([forms]!
[frmRecommendationsEntry]![combocrop]) Is Null)) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND
((qryRecommendationsBlockListBox.Commodity)=[forms]!
[frmRecommendationsEntry]![combocrop]) AND (([forms]!
[frmRecommendationsEntry]![txtConventional]) Is Null)) OR
(((qryRecommendationsBlockListBox.LotNumber)=[forms]!
[frmRecommendationsEntry]![lotnumber]) AND (([forms]!
[frmRecommendationsEntry]![combocrop]) Is Null) AND (([forms]!
[frmRecommendationsEntry]![txtConventional]) Is Null))
ORDER BY qryRecommendationsBlockListBox.BlockName,
qryRecommendationsBlockListBox.Variety;
PLEASE HELP
What am I typing incorrectly. I can't find it.
Heidi