findrecord

G

Guest

using code to search for a string
however not sure what to do if it doesnt find it
eg.
[txtCustName].setfocus
DoCmd.FindRecord comboCustName

If the customers name cannot be found i want to display a message
box.....but not sure how to (eg. If comboCustName Not found Then MsgBox)
 
G

Guest

cool thnx that works.
wish to expand to find next record
but wont except rs.findnext

Private Sub comboCustRef_AfterUpdate() 'search for cust ref
On Error GoTo Err_ComboCustRef 'on error
Dim rs As DAO.Recordset

txtCustID.SetFocus 'set focus

If Not IsNull(Me.comboCustRef) Then 'Search in the clone set
Set rs = Me.RecordsetClone
If Me.txtCustID = Me.comboCustRef Then 'if combo is same -
search for next record
rs.FindNext '!!!!!!!!!!!!!HERE IS THE PROBLEM?!?
If rs.NoMatch Then 'no record found
MsgBox "There are no more records for this school name."
End If
Else
rs.FindFirst "[txtCustID] = " & Me.comboCustRef 'search
records
If rs.NoMatch Then 'no record found
MsgBox "There is no record for this school, please check and
try again."
Else
Me.Bookmark = rs.Bookmark 'Display the found record in
the form.
End If
End If
Set rs = Nothing
End If


Exit_ComboCustRef: 'error handling
Exit Sub

Err_ComboCustRef:
MsgBox Err.Description
Resume Exit_ComboCustRef


End Sub

--
thanks
liz


Allen Browne said:
Instead of FindRecord, use FindFirst on the RecordsetClone of the form. You
can then test its NoMatch property to see if it found a result or not.

Here's an example:
Using a Combo Box to Find Records
at:
http://allenbrowne.com/ser-03.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

liz said:
using code to search for a string
however not sure what to do if it doesnt find it
eg.
[txtCustName].setfocus
DoCmd.FindRecord comboCustName

If the customers name cannot be found i want to display a message
box.....but not sure how to (eg. If comboCustName Not found Then MsgBox)
 
A

Allen Browne

Set the form's Filter so that it contains only matches.
The user can then navigate easily to the record they want.

An advantage is that you can provide as many combos and text boxes as you
want, and they user can use whichever ones they want. Here's an example you
can download to see how it works:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

liz said:
cool thnx that works.
wish to expand to find next record
but wont except rs.findnext

Private Sub comboCustRef_AfterUpdate() 'search for cust ref
On Error GoTo Err_ComboCustRef 'on error
Dim rs As DAO.Recordset

txtCustID.SetFocus 'set focus

If Not IsNull(Me.comboCustRef) Then 'Search in the clone set
Set rs = Me.RecordsetClone
If Me.txtCustID = Me.comboCustRef Then 'if combo is same -
search for next record
rs.FindNext '!!!!!!!!!!!!!HERE IS THE PROBLEM?!?
If rs.NoMatch Then 'no record found
MsgBox "There are no more records for this school name."
End If
Else
rs.FindFirst "[txtCustID] = " & Me.comboCustRef 'search
records
If rs.NoMatch Then 'no record found
MsgBox "There is no record for this school, please check
and
try again."
Else
Me.Bookmark = rs.Bookmark 'Display the found record
in
the form.
End If
End If
Set rs = Nothing
End If


Exit_ComboCustRef: 'error handling
Exit Sub

Err_ComboCustRef:
MsgBox Err.Description
Resume Exit_ComboCustRef


End Sub

--
thanks
liz


Allen Browne said:
Instead of FindRecord, use FindFirst on the RecordsetClone of the form.
You
can then test its NoMatch property to see if it found a result or not.

Here's an example:
Using a Combo Box to Find Records
at:
http://allenbrowne.com/ser-03.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

liz said:
using code to search for a string
however not sure what to do if it doesnt find it
eg.
[txtCustName].setfocus
DoCmd.FindRecord comboCustName

If the customers name cannot be found i want to display a message
box.....but not sure how to (eg. If comboCustName Not found Then
MsgBox)
 

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

Top