FindRecord

F

FatMax

Form is based on tblNames and includes the field LastName.

On the form I've placed an unbound text box cboSearch and a command
button cmdSearch. Macro attached to the buttons OnClick property has
two actions
GoToControl (arguement: [LastName])
FindRecord (argument: FindWhat=[cboSearch])

Works OK but if no last name matches search criteria nothing happens!
Is it possible to display an error message from the macro if the last
name doesn't exist or do I need to go to code. Would prefer macro as
this is supposed to be used to show 14 year old students some of the
*fun* things that can be done with Access.

FatMax
Suggestions for any other *fun* things welcome!!!
 
S

Sandra Daigle

To do any error handling you need to go to VBA. The code would be something
like this:

with me.recordsetclone
.findfirst "Lastname=""" & me.cboSearch & """"
if not .nomatch then
me.bookmark=.bookmark
else
msgbox "No Match"
endif
End with

In English, this uses a clone of the form's recordset to find a record that
has the LastName field matching cboSearch. If one is found, the form
navigates to the found record. If not, an error is displayed.

On this line:

.findfirst "Lastname=""" & me.cboSearch & """"

There are 3 double quote characters before the first & and 4 after the
second &. These are required if LastName is a text field.
 
F

FatMax

Many thanks for the advice. Sorry to both you and Allen Browne as
original post *should* have read txtSearch!!!!

My bad. I solved the problem in the macro using a condition
[LastName]<>[txtSearch] at the end.

Much appreciate both your time though :)

FatMax

Sandra Daigle said:
To do any error handling you need to go to VBA. The code would be something
like this:

with me.recordsetclone
.findfirst "Lastname=""" & me.cboSearch & """"
if not .nomatch then
me.bookmark=.bookmark
else
msgbox "No Match"
endif
End with

In English, this uses a clone of the form's recordset to find a record that
has the LastName field matching cboSearch. If one is found, the form
navigates to the found record. If not, an error is displayed.

On this line:

.findfirst "Lastname=""" & me.cboSearch & """"

There are 3 double quote characters before the first & and 4 after the
second &. These are required if LastName is a text field.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Form is based on tblNames and includes the field LastName.

On the form I've placed an unbound text box cboSearch and a command
button cmdSearch. Macro attached to the buttons OnClick property has
two actions
GoToControl (arguement: [LastName])
FindRecord (argument: FindWhat=[cboSearch])

Works OK but if no last name matches search criteria nothing happens!
Is it possible to display an error message from the macro if the last
name doesn't exist or do I need to go to code. Would prefer macro as
this is supposed to be used to show 14 year old students some of the
*fun* things that can be done with Access.

FatMax
Suggestions for any other *fun* things welcome!!!
 
S

Sandra Daigle

No problem, I would still recommend teaching VBA over macros any day. Macros
are very limited in what they can do and you can't really extend that
experience to anything else. On the other hand, VBA is a nice way to step
into structured programming. You can do quite a bit with fairly simple code
and then when you need to, you can also get into more complex types of code
and structure. Just my $.02 worth!

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Many thanks for the advice. Sorry to both you and Allen Browne as
original post *should* have read txtSearch!!!!

My bad. I solved the problem in the macro using a condition
[LastName]<>[txtSearch] at the end.

Much appreciate both your time though :)

FatMax

Sandra Daigle said:
To do any error handling you need to go to VBA. The code would be
something like this:

with me.recordsetclone
.findfirst "Lastname=""" & me.cboSearch & """"
if not .nomatch then
me.bookmark=.bookmark
else
msgbox "No Match"
endif
End with

In English, this uses a clone of the form's recordset to find a
record that has the LastName field matching cboSearch. If one is
found, the form navigates to the found record. If not, an error is
displayed.

On this line:

.findfirst "Lastname=""" & me.cboSearch & """"

There are 3 double quote characters before the first & and 4 after
the second &. These are required if LastName is a text field.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Form is based on tblNames and includes the field LastName.

On the form I've placed an unbound text box cboSearch and a command
button cmdSearch. Macro attached to the buttons OnClick property has
two actions
GoToControl (arguement: [LastName])
FindRecord (argument: FindWhat=[cboSearch])

Works OK but if no last name matches search criteria nothing
happens! Is it possible to display an error message from the macro
if the last name doesn't exist or do I need to go to code. Would
prefer macro as this is supposed to be used to show 14 year old
students some of the *fun* things that can be done with Access.

FatMax
Suggestions for any other *fun* things welcome!!!
 

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