Hi Matt, Hi Ricky
Ahh .... seems I didn't quite explain my problem properly. Sorry 'bout that.
I've gotten past the problem of knowing how many records I have returned, now I'm stuck trying to get the right record to display on the form. (There are two forms - the first is the search form, the second is a form that displays all the data for the record selected from the search form).
Here's the code I'm trying to work with:
CODE
Private Sub cmdSearch_Click()
' Search for a Supplier with the supplied criteria
On Error GoTo Err_cmdSearch_Click
Dim where As Variant
Dim intNum As Integer
where = Null
where = "[SuppName] like " + "'*" + Me![txtSupplierName] + "*'"
' Check how many suppliers are being returned.
' If only one - go back to Supplier form and display.
' If more than one, let user pick from this screen.
' If zero - display error message.
Select Case DCount("[SuppName]", "tblSuppliers", where)
Case 0
' No records matched the selection criteria
MsgBox "There are no Suppliers matching your request" & Chr$(13) _
& " Please try again.", vbCritical, "No matches"
txtSupplierName.SetFocus
Case Is < 2
' Only one record matched
Me.lblListBoxSupplier.Visible = True
Me.lblListBoxHeader.Visible = True
Me.lstSuppliers.Visible = True
where = ("Select PKSupplier, SuppName from tblSuppliers " _
& (" where " + (where)))
Me.lstSuppliers.RowSource = where
strLinkCriteria = "[PKSupplier]=" & Me.lstSuppliers
' Here is where I am not getting the right code .....
MsgBox strLinkCriteria
DoCmd.Close
DoCmd.OpenForm "frmSuppliers", , , strLinkCriteria
Case Else
' More than one result, so display the results in the listbox
Me.lblListBoxSupplier.Visible = True
Me.lblListBoxHeader.Visible = True
Me.lstSuppliers.Visible = True
where = ("Select PKSupplier, SuppName from tblSuppliers " _
& (" where " + (where)) & "ORDER BY [tblSuppliers].[SuppName];")
Me.lstSuppliers.RowSource = where
End Select
Exit_cmdSearch_Click:
Exit Sub
Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub ' cmdSearch_Click
I can't seem to get the case of just one record to work. I seem to be missing the knowledge on how to get the key (PKSupplier) from the search and pass it back to the second form to display the full record.
Thanks in advance for your assiatance.
Robert.