Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display something in combo box if query returns nothing

Status
Not open for further replies.

marcin2k

Programmer
Jan 26, 2005
62
CA
I have a query that populates my combobox. But if no results are returned instead of leaving the combobox empty I want to set it to display something that I will pick.

Thanks Marcin
 
Hi
Maybe:
Code:
If Me.[i]cboCombo[/i].RowSource <> "" Then
    Set rs = CurrentDb.OpenRecordset(Me.[i]cboCombo[/i].RowSource)
    If rs.BOF Then
        strRecError = "No Records. "
    End If
Else
    strRecError = "No recordset. "
End If
If strRecError <> "" Then
    MsgBox (strRecError & "Pick one of these.")
    'Me.[i]cboCombo[/i].RowSource="Some Other Query"
End If
End Sub
 
or another option to display nothing found

strsql = "select field1, field2 from table Me.cboCombo.RowSource = strsql
If Me.cboCombo.ListCount < 1 Then
strsql = strsql & " union select 'Nothing' as field1, 'found' as field2 from table"
Me.cboCombo.RowSource = strsql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top