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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindRecord Problem when no record Found

Status
Not open for further replies.

Modex

Programmer
Sep 15, 2002
155
0
0
GB
Hi All,

I have a text box on a form where a User can type in a name of a unit and expect to jump to the record containing that unit.

I use the very simple code:-

docmd.gotoontrol "Units"
docmd.findrecord TextBoxName

This works fine if the unit is found, however if the unit is not found then the cursor just jumps to the record thats on the screen at the time.

That is going to cause some problems with data being added to records incorrectly (Basically because the cursors moved so the user thinks its found the record, they don't bother checking to see if its the right record)

What I need to be able to do is put up a messagebox to say record not found and this is where I'm stuck.

I found one thread on Tek-Tips that recomended using DCount to do this, but I couldnt get it to work whatever I tried.

If anyone has done this before or knows a better way of doing it, could you please help me.

For Clarities sake
Table : DataCapture
TextBox : SearchOne
Field : UnitName

Many thanks in advance

ModeX
 
One approach would be to use a combo box to find the record rather than a text box. This will prevent users selecting a record that doesn't exist.
You can add a combo box using the wizard and using the 'find a record in my form' option.
 
Take a look at the RecordsetClone, FindFirst, NoMatch and Bookmark methods/properties of the DAO.Recordset and Form objects.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm not sure the .FindRecord method of the docmd object has that possibility. You may consider the .FindFirst method of the DAO recordset in stead:

[tt]dim rs as dao.recordset
set rs=me.recordsetclone
rs.findfirst "UnitName='" & me!SearchOne & "'"
if rs.nomatch then
msgbox "not found"
else
me.bookmark=rs.bookmark
end if[/tt]

- perhaps also add a test for null on the text control prior to the search?

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top